-1

Hi I want to send data to server in post method. I know it is simple question but I didn't get well document for this. I had method which sends data to server but it is using ajax. I want to send data without ajax how to do that? Here is my code.

 $.ajax({
                type: "POST",
                contentType:"application/x-www-form-urlencoded; charset=UTF-8",
                url: clientDetailURL,
                data: finalclientDetailParam
                }).done(function( msg1 )
                {
                         var clientDetailResponse = msg1;
                         console.log("Client detail response is:"+clientDetailResponse);
                 });
PPD
  • 5,072
  • 11
  • 45
  • 82
  • 4
    _'send data without using ajax...'_ like a form submit for a post, or a url redirect for a get? – nbrooks Jul 08 '12 at 08:17
  • @ OnheironHi I want to develop this application in phonegap. It must support blackberry and bada. But In blackberry version5 it doesn't support ajax. In version 6 it works fine – PPD Jul 08 '12 at 08:18
  • 1
    See this link, should help: http://stackoverflow.com/a/133997/803925 – nbrooks Jul 08 '12 at 08:18
  • All your base are belong to method="post" – The Muffin Man Jul 08 '12 at 08:24
  • @PramodD: Blackberry doesn't support AJAX? That seems either very unlikely or very disappointing. Either way, there's nothing that makes AJAX special. It's just sending HTTP requests to a server resource. If you can't use AJAX then you'll still need to send HTTP requests to a server resource. Those requests will just have to be page-level in a browser instead of "behind-the-scenes" in JavaScript code. And, of course, the server will have to be prepared to process those requests and return usable responses. – David Jul 08 '12 at 08:27

1 Answers1

0

Ok Now I am posting data like this:

function post_to_url(path, params, method) {

console.log ("Inside post_to_url>>>>>>>>");
method = method || "post"; // Set method to post by default, if not specified.

// The rest of this code assumes you are not using a library.
// It can be made less wordy if you use one.
var form = document.createElement("form");
form.setAttribute("method", method);
form.setAttribute("action", path);

for(var key in params) {
    if(params.hasOwnProperty(key)) {
        var hiddenField = document.createElement("input");
        hiddenField.setAttribute("type", "hidden");
        hiddenField.setAttribute("name", key);
        hiddenField.setAttribute("value", params[key]);

        form.appendChild(hiddenField);
     }
}

document.body.appendChild(form);
form.submit();

}

and calling this method as:

function handleLogin()
{

var form = $("#loginForm");    
 var u = $("#username", form).val();
var p = $("#password", form).val();
var d = $("#dob", form).val();

if(u != '' && p!= '')
{
    var finalStr = u+encodeURIComponent("|^")+p+encodeURIComponent("|^")+encodeURIComponent("|^")+"X"+encodeURIComponent("|^")+d+encodeURIComponent("|^")+"1.0"+encodeURIComponent("|^|$");

    var encodedURL = encodeURI(intranetUrl+"customer/Ri_logon.asp?requestString=");
    var parameters =  decodeURIComponent(finalStr);
    console.log("before calling post_to_url method");
    post_to_url(encodedURL,parameters,'post');




}


else
{

    alert("You must enter a username and password", function() {});
    $("#submitButton").removeAttr("disabled");
}


}

But now I am getting output from server as :"Not an object". it comes from server when paramaeters paased or special characters are not encoded perfectly. But I had encoded parameter well like in my original question above. Then why is it so?

PPD
  • 5,072
  • 11
  • 45
  • 82