阿贾克斯帖子内容类型

阿贾克斯帖子内容类型

本文介绍了阿贾克斯帖子内容类型:应用程序/ JSON的阻塞请求的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的Ajax请求:

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");
      }
      });

如果我没有precise内容类型,我看不到了我与萤火虫的要求。而此时我想补充一个内容类型相反,我可以看到POST请求(有错误导致我的网址是假的),但在我的头中的内容类型是默认的URL连接codeD格式。

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.

我要的是通过JSON数据发送给我的窗体的详细信息。感谢名单的帮助

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

推荐答案

您拼错的contentType为内容类型

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");
    }
});

这篇关于阿贾克斯帖子内容类型:应用程序/ JSON的阻塞请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-31 02:00