我在我的 html 页面中使用了 jQuery ajax。
$.ajax({
url: 'search/' + page + '.html',
dataType: 'text',
success: function(data) {
$(".searchData").html(data);
$(".searchData").show("slow");
$(".searchImage").hide("slow");
},
error: function() {
$(".searchImage").show("slow");
$(".searchData").hide("slow");
}
});
没有服务器。我正在像 file:///C:/Documents%20and%20Settings/sss/Desktop/rrr/search.html
一样访问我的页面,它在 Firefox 中工作正常,但在 Chrome 和其他浏览器,显示:
No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access.
如何做到这一点?
最佳答案
因为浏览器有安全措施来阻止它。如果您想使用文件系统,您需要设置浏览器以允许它。
How to launch html using Chrome at "--allow-file-access-from-files" mode?
关于javascript - 如何在没有服务器的情况下使用 jQuery ajax,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21413378/