使用jsonp获取xml跨域 [英] use jsonp to get xml cross domain

查看:121
本文介绍了使用jsonp获取xml跨域的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想从另一台服务器读取xml到一个网页,我假设我的问题是同源政策,因此一个跨域问题。

I am trying to read xml into a webpage from another server, and I assume that my problem is Same-Origin Policy, and therefore a cross domain problem.

我有一点googling,似乎jsonp是向前的方式。
基于我在stackoverflow和另一个网站上找到的一些例子,这是我有,它不打服务器与xml。我可以在浏览器中查看xml。

I have a bit of googling and it seems that jsonp is the way forward. Based on some examples I found here on stackoverflow and another sites, this is what I have, and it does not "hit" the server with the xml. I can view the xml in a browser.

$(document).ready(function(){    
   $.ajax({
        type: 'GET',
        dataType: 'jsonp',                
        url: 'http://192.168.0.106:8111/getconfiguration?',
        success: function (xml) 
        { //do stuff with received xml 
        }});    

有任何建议吗?请记住,我是关于JS / JQuery的新手; o)

Any suggestions? please keep in mind that I am a newbie with regards to JS / JQuery ;o)

推荐答案

您没有访问服务器(例如,如果您正在使用api),您可以使用
YQL 将XML转换为jsonp,并使用自定义自定义YQL网址(其中嵌入了类似SQL的语句)从浏览器中查询yahoo服务器。这里有一个例子(对于zillow api):

If you don't have access to the server (if, for example, you're consuming an api) you can use YQL to convert your XML to jsonp and query the yahoo server from the browser using a custom custom YQL url (in which is embedded a SQL-like statement). Here's an example (for the zillow api):

$('document').ready(function(){
  $.ajax({
    url: 'http://query.yahooapis.com/v1/public/yql?q=select * from zillow.search where address = "1835 73rd Ave NE" and citystatezip = "98039" and zwsid = "X1-ZWz1cse68iatcb_13bwv"&format=json&diagnostics=true&env=http://datatables.org/alltables.env&callback=mydata',
    jsonpCallback: "mydata",
    success: function(results) {
      console.log(results.query.results.searchresults.response.results.result.zpid);
    },
    dataType: 'jsonp'
  });
});

这篇关于使用jsonp获取xml跨域的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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