来自本地文件系统的jQuery Ajax请求(Windows file:///) [英] jQuery Ajax request from local filesystem (Windows file:///)
问题描述
我正在尝试执行ajax请求,以获取在Windows Wamp Server上运行的"http://localhost/"
的内容.
I'm trying to do an ajax request to get the contents of "http://localhost/"
running on Windows Wamp Server.
该脚本是从这样的东西运行的:
The script is running from something like this:
file:///C:/my/path/index.html
我只是使用一个标准的$ .ajax请求来尝试获取localhost的内容:
I'm just using a standard $.ajax request to try and get the contents of localhost:
$.ajax({
type: 'GET',
url: 'http://localhost/',
success: function(data) {
alert('success');
}, error: function (data) {
alert('failed');
}
});
尽管如此,我还是无法成功...似乎是本地文件系统或某些问题.我不太确定.
I can't get it to be successful though... Seems to be some problem with the local filesystem or something. I'm not too sure.
推荐答案
问题已解决!
我只需要将此标头添加到 http://localhost/
I just had to add this header to my index.php file for http://localhost/
header('Access-Control-Allow-Origin: *');
无论如何,感谢您的帮助!
Thanks for your help anyhow guys!
这篇关于来自本地文件系统的jQuery Ajax请求(Windows file:///)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!