下面是我的Ajax请求:
$.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"); } });
如果我没有精确的内容类型,我就无法再看到Firebug的请求。相反,当我添加内容类型时,我可以看到POST请求(由于我的URL是false而出现错误),但在我的头中,内容类型默认是URL编码的表单。
我想要的是通过JSON数据发送表单的详细信息。谢谢你的帮助
您将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");
}
});