gpt4 book ai didi

Jquery POST XML 到 Rest 服务

转载 作者:行者123 更新时间:2023-12-01 07:15:26 25 4
gpt4 key购买 nike

我正在尝试使用 jquery 向 Restful 服务发送 POST 请求,其中发送的数据类型是 xml。

自从我通过 Chrome Rest 插件测试后,Rest 服务就可以工作了。我让它适用于 GET XML、GET JSON 和 POST JSON,但不适用于 POST XML。

这是代码。我没有收到任何错误,但调用不成功:

$.ajax({
type: "POST",
url: "http://[...]",
dataType: "xml",
contentType: "application/xml"
data: "<Category><categoryId>007</categoryId><categoryName>Ajax</categoryName></Category>",
success: function (res) {
alert("XML: it works!");
},
error: function (res) {
alert("XML: not working! " + res.statusText);
}
});

最佳答案

我知道这已经很旧了,但是你需要在data之前加一个逗号...

$.ajax({
type: "POST",
url: "http://[...]",
dataType: "xml",
contentType: "application/xml",
data: "<Category><categoryId>007</categoryId><categoryName>Ajax</categoryName></Category>",
success: function (res) {
alert("XML: it works!");
},
error: function (res) {
alert("XML: not working! " + res.statusText);
}
});

关于Jquery POST XML 到 Rest 服务,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19405121/

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