我试图将一些json发布到接受json的Web服务。
功能' basistech.serializeOptions()'此刻返回一个Javascript对象,但是 我可以很容易地返回一个字符串。请注意,即使我已经设置了“接受”'选项, 发送的标题是'接受:未定义',这会导致服务器端出现一些故障。
为什么我不能提供适当的mime类型'接受'?
$.ajax({
url : basistech.processText_url,
accepts : "application/json",
contentType : "application/json",
dataType : "json",
data : basistech.serializeOptions(),
type : "POST",
success : function(data) {
/* whatever */
},
error : function(jqXHR, textStatus, errorThrown) {
$("#submit-button").busy("hide");
alert(textStatus);
}
});
POST /r4dws/services/doc/processText HTTP/1.1
Host: localhost:15000
Connection: keep-alive
Content-Length: 1679
Origin: http://localhost:15000
X-Requested-With: XMLHttpRequest
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_7_2) AppleWebKit/535.2 (KHTML, like Gecko) Chrome/15.0.874.121 Safari/535.2
Content-Type: application/json
Accept: undefined
Referer: http://localhost:15000/r4dws/demo/xmltextbox.jsp
Accept-Encoding: gzip,deflate,sdch
Accept-Language: en-US,en;q=0.8
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.3
Cookie: JSESSIONID=AB76A77DF6906229D281A931D7D10C3C
Request Payload
(messed up)
答案 0 :(得分:4)
尝试这样....,
$.ajax({
url : basistech.processText_url,
headers: {
Accept : "application/json",
"Content-Type": "application/json"
},
dataType : "json",
data : basistech.serializeOptions(),
type : "POST",
success : function(data) {
/* whatever */
},
error : function(jqXHR, textStatus, errorThrown) {
$("#submit-button").busy("hide");
alert(textStatus);
}
});