Ajax Post Content Type : Application / Json Block the request

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


您将contentType拼写错误为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");
    }
});
链接地址: http://www.djcxy.com/p/8060.html

上一篇: 如何使用JSP / Servlet将文件上传到服务器?

下一篇: Ajax发布内容类型:应用程序/ Json阻止请求