做一个跨域请求XML从本地文件 [英] Make a Cross-Domain request for XML from a local file

查看:135
本文介绍了做一个跨域请求XML从本地文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道这甚至有可能。基本上我想加载客户端PC上的本地的HTML文件,并把它发出请求到远程服务器。由服务器提供的数据是XML。

I am not sure if this is even possible. Basically I want to load a local html file on a client PC and have it make a request to a remote server. The data served up by the server is XML.

当我说我加载一个文件,我的意思是出现在铬的URL为文件:/// E:/ ...

When I say I am loading a file, I mean the URL in chrome appears as "file:///E:/..."

这是最接近我已经读懂了能够加载XML。我检查了网络选项卡上的客户端和它的成功加载,我只是不能似乎得到XML转换成我可以检查一个元素:

This is the closest I have gotten to being able to load the XML. I inspected the network tab on the client end and its successfully loading, I just cant seem to get the XML into an element I can inspect:

 var script = document.createElement('script');

 script.setAttribute('src', 'http://xxx.xx.xx.xxx:xxxx/myxmldata');

 script.setAttribute('type', 'text/xml');

 script.setAttribute('id', 'myxml');

 document.getElementsByTagName('head')[0].appendChild(script); 

 var content = document.getElementById("myxml").responseText;// anything I can do here?

 console.log(content);

这是AJAX的解决办法工作了。我没有任何运气JSONP(这不是JSON,虽然)。

An AJAX solution would work too. I didn't have any luck with JSONP (this isn't JSON, though).

推荐答案

那么,如果您有与跨域策略出现问题,则可能需要建立某种形式的代理,会做的要求为您。 (它的pretty的简单制作)

Well, if you are having a problem with the cross domain policy, you might need to build some sort of proxy that will do the request for you. (Its pretty simple to make)

您有一个很好的例子在这里: http://dojotoolkit.org/reference-guide /dojo/xhrGet.html

You have a nice example here: http://dojotoolkit.org/reference-guide/dojo/xhrGet.html

希望它帮助。

这篇关于做一个跨域请求XML从本地文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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