不同的方式通过jQuery AJAX传递XML [英] Different ways to pass XML via jQuery AJAX
问题描述
我现在面临一个问题,得到的返回值(内容类型:为text / xml)。我可以通过直接访问获得的返回值这个网址:
I'm facing a problem to get return value (content-type: "text/xml"). I'm able to get return value by direct access this URL:
的https:// [DOMAIN_NAME] / MyFolder中/ myapi / XML =< XML版本='1.0'>< MyTasks><搜索>< /搜索>< / MyTasks>
请帮我纠正这些替代品,如果它是错误的(称为HTML位于 MyFolder中
),因为它时刻警惕'失败'。
Please help me to correct these alternatives if it is wrong (called in HTML located in MyFolder
) because it always alert 'Failed'.
$.ajax({
type : "GET",
url : "interface/?xml=<xml version='1.0'><MyTasks><Search></Search></MyTasks>",
dataType : "text/xml",
success : function(msg){
alert('Success');
}
error : function(msg) {
alert('Failed');
}
});
或
$.ajax({
type : "POST",
url : "interface/",
data : { xml: escape("<MyTasks><Search></Search></MyTasks>") },
dataType : "text/xml",
success : function(msg){
alert('Success');
}
error : function(msg) {
alert('Failed');
}
});
感谢你。
解决方案:
该接口由 HTTPS
进行访问,所以我改变了网址
参数为绝对URL。我也有使用XML
不是为text / xml
为的dataType
。它导致成功,谢谢大家。
The interface has to be accessed by https
, so I changed url
param to absolute URL. I also have to use "xml"
not "text/xml"
as its dataType
. It results Success, thank you.
推荐答案
要简化,我会做以下
让我们假设你正在使用称为script.php的PHP脚本。
Lets assume you are using a php script called script.php.
var xml_string = "<xml version='1.0'><MyTasks><Search></Search></MyTasks>";
$.get('script.php', {xml: xml_string}, function(){ //your success function
alert('success');
}).error(function(){ //your error function
alert("error");
});
这篇关于不同的方式通过jQuery AJAX传递XML的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!