做一个跨域请求XML从本地文件做一个、本地文件、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上的本地的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

希望它帮助。

阅读全文

相关推荐

最新文章