0

Here is my Ajax request :

$.ajax({
      url: '',
      type: 'POST',
      data: JSON.stringify({country : jcountry, region : jregion, from : jfrom, to : jto, currency : jcurrency}),
      processData : false,
      Content-Type : 'application/json' ,  
      dataType: 'json',
      success: function() {
      alert("success")
      $.mobile.changePage("menu1.html");
      },
      error: function (xhr, ajaxOptions, thrownError) {
      alert( "Error: " + xhr.status + "\n" +
             "Message: " + xhr.statusText + "\n" +
             "Response: " + xhr.responseText + "\n" + thrownError);
      $.mobile.changePage("menue2.html");
      }
      });

If I don't precise a Content Type, I can't see anymore my request with firebug. At the opposite when I add a Content type, I can see the POST request (with an error cause my URL is false) but in my header the content type is by default the url encoded form.

What I want is send the details of my form via JSON data. Thanx for your help

1 Answer 1

0

You have misspelled the contentType to content-Type

$.ajax({
    url: '',
    type: 'POST',
    data: JSON.stringify({
        country: jcountry,
        region: jregion,
        from: jfrom,
        to: jto,
        currency: jcurrency
    }),
    processData: false,
    ContentType: 'application/json',
    dataType: 'json',
    success: function () {
        alert("success")
        $.mobile.changePage("menu1.html");
    },
    error: function (xhr, ajaxOptions, thrownError) {
        alert("Error: " + xhr.status + "\n" +
            "Message: " + xhr.statusText + "\n" +
            "Response: " + xhr.responseText + "\n" + thrownError);
        $.mobile.changePage("menue2.html");
    }
});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.