[英]Why doesn't Javascript work on XML if it's external
I did some manipulation with an XML database through Javascript. 我通过Javascript对XML数据库进行了一些操作。 XML was within the HTML code and it worked fine, but when I wanted to use XLST, I had to make XML external. XML在HTML代码中,并且工作正常,但是当我想使用XLST时,我不得不将XML置于外部。 Upon doing so, Javascript lost all it's function, even though the ID of the XML file which I used to call it in a function remained the same. 这样一来,即使我曾经在函数中调用过的XML文件的ID保持不变,Javascript也失去了所有功能。
Is there a way around this? 有没有解决的办法?
You need some intermediate device to go between the JavaScript and XML file (server-side code of some fashion most-likely). 您需要一些中间设备才能在JavaScript和XML文件之间(最有可能采用某种方式的服务器端代码)。 JavaScript cannot directly manage flat files (which is what the "XML database" you reference is). JavaScript无法直接管理平面文件(这是您引用的“ XML数据库”的含义)。
Work-flow would be in the following [pseudo-]pattern: 工作流程将采用以下[伪]模式:
if you already have a go-between, make sure you're on the same domain name when making calls to and from the server. 如果已经有中间人,则在往返于服务器的呼叫时,请确保您使用相同的域名。 As a commenter pointed out, JavaScript cannot go between domain levels natively; 正如评论者所指出的那样,JavaScript本身不能在域级别之间进行转换。 Instead you'd have to use either something like JSONP or setup the Access-Control-*
headers on the remote server, 相反,您必须使用JSONP之类的东西或在远程服务器上设置Access-Control-*
标头,
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.