jQuery ajax 发布到 Web 服务
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/3099369/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
jQuery ajax post to web service
提问by Jan Johansen
$(document).ready(function() {
$.ajax({ type: "POST",
url: "/getprojects.ashx",
data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
dataType: "text/xml",
cache: false,
error: function() { alert("No data found."); },
success: function(xml) {
alert("it works");
alert($(xml).find("project")[0].attr("id"));
}
});
});
My problem is i get some data back but i can't seem to get it displayed.
我的问题是我取回了一些数据,但似乎无法显示。
回答by Claude Vedovini
dataType
should be the type of what you receive but contentType
should be the mime-type of what you are sending, the following should be ok:
dataType
应该是您收到的类型,但contentType
应该是您发送的内容的 mime 类型,以下应该没问题:
$(document).ready(function() {
$.ajax({ type: "POST",
url: "/getprojects.ashx",
data: "<formData client=\"\" year=\"\" categories=\"\" tags=\"\" freeText=\"\" count=\"34\" page=\"1\"></formData>",
contentType: "text/xml",
dataType: "xml",
cache: false,
error: function() { alert("No data found."); },
success: function(xml) {
alert("it works");
alert($(xml).find("project")[0].attr("id"));
}
});
});
回答by jAndy
Your dataType
seems to be wrong. It should look like
你的dataType
好像错了。它应该看起来像
dataType: "xml"
Your data
structure also looks pretty wierd. Have a look at .serializeArray(). It should be standard query string foo=bar&test=blaetc.
你的data
结构看起来也很奇怪。看看.serializeArray()。它应该是标准查询字符串foo=bar&test=bla等。
If the success handler
gets executed, try to lookup your xml
variable plain, without
operating on it with .find()
or whatever. Still empty?
如果success handler
被执行,请尝试查找您的xml
变量plain,而不要对其进行操作.find()
或其他任何操作。还是空的?