我有以下的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