XMLHttpRequest;跨源请求仅支持以下协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource [英] XMLHttpRequest; Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource
问题描述
当我尝试执行 ajax 调用时,我在下面的 chrome 上遇到了错误.
<块引用>XMLHttpRequest 无法加载 javascript:;.跨源请求是仅支持协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource.
代码如下:
$.ajax({类型:POST",数据:{pvalue:pid},缓存:假,url: "xxx.in/yy/ajax.php",成功:功能(数据){$modal.find('.edit-content').html(data);}
对该特定错误消息的所有研究表明,主机网页未通过 http://URL 加载,可能是文件:URL.默认情况下,浏览器不会允许来自 file: URL 的跨源请求.
如果您想使用 ajax 请求,您需要通过您的网络服务器加载网页,而不是通过文件系统.
以下是有关该特定错误的一些其他问题和答案,这些问题和答案都指向用于加载页面的 URL 类型错误.
https://groups.google.com/forum/#!topic/tincr-for-chrome-devtools/nA9k2qh7F-g
When I try to do a ajax call, I got the error on chrome below.
XMLHttpRequest cannot load javascript:;. Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https, chrome-extension-resource.
Here is code:
$.ajax({
type: "POST",
data: {pvalue : pid},
cache: false,
url: "xxx.in/yy/ajax.php",
success: function(data)
{
$modal.find('.edit-content').html(data);
}
All research into that specific error message suggests that the host web page is not being loading via an http:// URL and is probably a file: URL. The browser will not, by default, permit cross origin requests from a file: URL.
You need to load the web page through your web server, not via the file system if you want to use ajax requests.
Here are some other questions and answers about that specific error that all point to the wrong type of URL being used to load the page.
"Cross origin requests are only supported for HTTP." error when loading a local file
React.js: Example in tutorial not working
Cross origin requests are only supported for HTTP but it's not cross-domain
https://groups.google.com/forum/#!topic/tincr-for-chrome-devtools/nA9k2qh7F-g
这篇关于XMLHttpRequest;跨源请求仅支持以下协议方案:http、data、chrome、chrome-extension、https、chrome-extension-resource的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!