不同的方式通过jQuery AJAX传递XML [英] Different ways to pass XML via jQuery AJAX

查看:139
本文介绍了不同的方式通过jQuery AJAX传递XML的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我现在面临一个问题,得到的返回值(内容类型:为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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆