我有一个包含以下代码的code.html文件.
$.ajax({ type: "POST",datatype: "JSONP",url: "path",success: function(msg){ var e = document.createElement("div"); e.id = "ads"; document.body.appendChild(e); $("#ads").html(msg); } });
当我在浏览器中打开code.html文件时,它会出错:@H_502_4@
**"XMLHttpRequest cannot load file://..... Origin null is not allowed by Access-Control-Allow-Origin."**
请帮我!!如何避免这个问题@H_502_4@
我将做两个假设:
>你可能正在使用chrome
>您正在从文件系统打开文件(即双击)@H_502_4@
然后,这个问题是XMLHttpRequest Origin null is not allowed Access-Control-Allow-Origin for file:/// to file:/// (Serverless)的重复@H_502_4@
浏览器阻止跨站点脚本.见:https://developer.mozilla.org/en-US/docs/HTTP_access_control@H_502_4@