試圖讓jQuery來張貼JSON到服務器:發帖JSON使用jQuery
$.ajax({
url: "/path/to/url",
type: "POST",
dataType: "json",
contentType: "json",
data: {"foo": "bar"},
success: function(){
alert("success :-)");
},
error: function(){
alert("fail :-(");
}
});
問題是數據出現在服務器"foo=bar"
而不是期望"{\"foo\":\"bar\"}
上。
我以爲指定dataType或contentType參數會做的伎倆,但沒有。
任何人都知道正確的ajax配置? [或者在發佈之前將[數據]參數序列化爲JSON的方式]
謝謝!