gpt4 book ai didi

javascript - 跨源请求只支持HTTP,不支持跨域

转载 作者:IT王子 更新时间:2023-10-29 02:45:44 26 4
gpt4 key购买 nike

我正在使用此代码发出 AJAX 请求:

$("#userBarSignup").click(function(){
$.get("C:/xampp/htdocs/webname/resources/templates/signup.php",
{/*params*/},
function(response){
$("#signup").html("TEST");
$("#signup").html(response);
},
"html");

但是在 Google Chrome JavaScript 控制台中,我不断收到此错误:

XMLHttpRequest cannot load file:///C:/xampp/htdocs/webname/resources/templates/signup.php. Cross origin requests are only supported for HTTP.

问题是 signup.php 文件托管在我的本地网络服务器上,这是所有网站运行的地方,因此它不是跨域的。

我该如何解决这个问题?

最佳答案

我很幸运通过以下开关启动了 chrome:

--allow-file-access-from-files

在 os x 上尝试(如果复制粘贴,请重新键入破折号):

open -a 'Google Chrome' --args -allow-file-access-from-files

在其他 *nix 上运行(未测试)

 google-chrome  --allow-file-access-from-files

或在 Windows 上编辑 chrome 快捷方式的属性并添加开关,例如

 C:\ ... \Application\chrome.exe --allow-file-access-from-files

到“目标”路径的末尾

关于javascript - 跨源请求只支持HTTP,不支持跨域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8449716/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com