问题jQuery的AJAX跨域XML响应问题、jQuery、AJAX、跨域

由网友(久居我心你却从未交房租)分享简介:下面是我的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/se...

下面是我的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 作为的

阅读全文

相关推荐

最新文章