问题jQuery的AJAX跨域XML响应 [英] issue with jquery ajax cross domain xml response

查看:207
本文介绍了问题jQuery的AJAX跨域XML响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

下面是我的code访问 XML 从网站

Here is my code to access xml from a website

$(document).ready(function () {
    $.ajax({
        type: "GET",
        url: "http://rxnav.nlm.nih.gov/REST/Ndfrt/search?conceptName=TESTOSTERONE",
        dataType: "xml",
        success: xmlParser

      });
});

function xmlParser(xml) { 
    $(xml).find("entry").each(function () {
        $(".entirecont").append($(this).find('inputConceptName').text());
    });
}

它的正常工作地方,当我按下这个code生产它给我的跨域限制。

it's working fine in local when i push this code to production it's giving me the cross domain restrictions.

下面是的jsfiddle

我知道这是一个跨域请求,但是,我该如何解决?

I know it's a cross domain request but, how can i fix it??

感谢

推荐答案

在XML中,一个真正的跨域请求您的唯一真正的选择是,如果该服务器支持的 CORS ,让你的出身,你的浏览器支持它。 (如果他们有一个 JSONP 的选择,虽然,那会更容易些。可悲的是,虽然咋一看他们API网页建议他们只支持XML和JSON,而不是JSONP。但是,看看自己,不要把我的话,我没有做一个详细的阅读。这是有点奇怪,如果他们支持JSON但不是JSONP,在我看来, 。)

With XML, your only real option for a true cross-domain request is if that server supports CORS, allows your origin, and your browser supports it. (If they have a JSONP option, though, that would be easier. Sadly, though, a quick look at their API page suggested they only support XML and JSON, not JSONP. But look for yourself, don't take my word for it, I didn't do a detailed read. It's slightly odd if they support JSON but not JSONP, in my view.)

另一种选择,我有时会听到讨论,但做的是使​​用 YQL 作为的cross-domain代理

Another option I've sometimes heard discussed but have done is using YQL as a cross-domain proxy.

当然,你也可以运行自己的服务器,使请求的的,并有其查询rxnav.nlm.nih.gov饲料,并返还给您。那么SOP不来了进去。

Of course, you can also run your own server, make the requests to it, and have it query the rxnav.nlm.nih.gov feed and return it to you. Then the SOP doesn't come into it.

边注:要使用CORS与jQuery在IE8或者IE9,你需要一个插件在处理使用特殊 XDomainRequest 对象(IE8和IE9的 XMLHtt prequest 对象没有做CORS)。 IE10终于解决了。

Side note: To use CORS with jQuery in IE8 or IE9, you need a plug-in that handles using the special XDomainRequest object (IE8 and IE9's XMLHttpRequest object doesn't do CORS). IE10 finally fixes that.

这篇关于问题jQuery的AJAX跨域XML响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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