gpt4 book ai didi

jquery - 使用 JQuery 发送 json 内容,MIME 类型和序列化出现问题

转载 作者:行者123 更新时间:2023-12-01 03:22:54 25 4
gpt4 key购买 nike

我正在尝试将一些 json POST 到接受 json 的 Web 服务。

函数“basistech.serializeOptions()”此时返回一个 Javascript 对象,但是我可以轻松地返回一个字符串。请注意,即使我设置了“接受”选项,发送的 header 是“Accept: undefined”,这会导致服务器端出现一些故障。

为什么我不能在“accepts”中给出正确的 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)

最佳答案

尝试这样......,

$.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);
}
});

关于jquery - 使用 JQuery 发送 json 内容,MIME 类型和序列化出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8198277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com