English 中文(简体)
JSonson 在 Safari 中的文件负荷, 但不是在 Chrome 中的文件负荷
原标题:JSON file loads in Safari but not in Chrome

当我在 Safari 中运行我的页面时, JSON 文件已成功载入, 但在 Chrome 中运行时失败 。 在 Chrome 的错误控制台中, 它显示错误 :

XMLHttpRequest cannot load file:///C:/Users/290851/Desktop/json-eg/test.json. Origin null is not allowed by Access-Control-Allow-Origin.

我还测试了JSON的档案,而且文件是有效的。谁能告诉我为什么发生这种情况,有什么解决办法?

最佳回答

您是否听说过 < a href=>" "http://en.wikipedia.org/wiki/Same_ground_policy" rel=" nofollow noreferrer" >Cross Docause Access ?

您将无法在其它域名中调用该服务( 您的 Jason 文件 ) 。 Chrome 向您警告脚本和服务位于不同的域( 不同的网站) 。 这是现代浏览器的安全功能, 防止了这些网络通话 。

如果你同时有剧本和 Jason 文件 和 Jason 文件 在同一文件夹中, 我猜它应该是世界性的。 试一试看看 。

你需要使用代理或JSONP 来解决这个问题。

"https://stackoverflow.com/search?q=cross%20domain%20javascript"。>以前也问过许多类似的问题

问题回答

暂无回答




相关问题
how to represent it in dtd?

I have two element action and guid. guid is a required field when action is add. but when action is del it will not appear in file. How to represent this in dtd ?

.Net application configuration add xml-data

I need to add xml-content to my application configuration file. Is there a way to add it directly to the appSettings section or do I need to implement a configSection? Is it possible to add the xml ...

XStream serializing collections

I have a class structure that I would like to serialize with Xstream. The root class contains a collection of other objects (of varying types). I would like to only serialize part of the objects that ...

MS Word splits words in its XML format

I have a Word 2003 document saved as a XML in WordProcessingML format. It contains few placeholders which will be dynamically replaced by an appropriate content. But, the problem is that Word ...

Merging an XML file with a list of changes

I have two XML files that are generated by another application I have no control over. The first is a settings file, and the second is a list of changes that should be applied to the first. Main ...

How do I check if a node has no siblings?

I have a org.w3c.dom.Node object. I would like to see if it has any other siblings. Here s what I have tried: Node sibling = node.getNextSibling(); if(sibling == null) return true; else ...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

热门标签