来自本地文件系统的 jQuery Ajax 请求(Windows 文件:///) [英] 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.
脚本是这样运行的:
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.
推荐答案
问题解决了!
我只需将此标头添加到我的 index.php 文件中以获取 http://localhost/
I just had to add this header to my index.php file for http://localhost/
header('Access-Control-Allow-Origin: *');
谢谢你们的帮助!
这篇关于来自本地文件系统的 jQuery Ajax 请求(Windows 文件:///)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!