我有以下的jQuery在IIS目录托管:最简单的jQuery阿贾克斯无法找到JSON文件
$(function() {
$.ajax({
"url": "sample.json",
"type": "get",
"dataType": "json",
"success": function(data) {
console.log(data);
},
"error": function(jqXHR, status, error) {
console.log("status:",status, "error", error);
}
}) ;
});
当我浏览html文件,我得到这个在JS控制台:
GET http://localhost/Ajax/sample.json 404 (Not Found) jquery-1.9.0.min.js:3
status: error error Not Found app.js:18
它在目录中的权利。当我使用/sample.json时,得到:
GET http://localhost/sample.json 404 (Not Found) jquery-1.9.0.min.js:3
status: error error Not Found
如何获取它以查找本地文件并执行ajax调用?
你能直接使用浏览器在地址栏中输入URL来访问文件吗?如果是,您使用哪个网址? – Alexander 2013-02-11 19:02:15
是的,但它无法处理由于扩展配置,您请求的页面无法投放。如果页面是脚本,请添加处理程序。如果文件应该被下载,添加一个MIME映射。 http://localhost/Ajax/sample.json – 2013-02-11 19:16:33
然后,现在你知道该怎么做 – Alexander 2013-02-11 19:21:00