我使用的是CodeIgniter
和$.getJson
試圖加載一個JSON文件,在我的腳本的同一文件夾中。錯誤404的getJSON獲取本地JSON文件笨
我已經嘗試改變我的網站的根目錄下,並在應用程序文件夾中的.htaccess內容,改變加載路線
.$getJson("<?php echo base_url...")
並沒有什麼工作。它總是顯示了同樣的錯誤:
jquery.min.js:4 GET http://www.my-site.com/index.php/admin_cotrol/shop_list.json 404 (Not Found)
這裏是我的腳本:
$(window).load(function() {
$('#search').keyup(function() {
var searchField = $('#search').val();
var regex = new RegExp(searchField, "i");
var output = '<div class="row">';
var count = 1;
$.getJSON("shop_list.json", function(data) {
$.each(data, function(key, val) {
if ((val.name.search(regex) != -1) || (val.location.search(regex) != -1)) {
output += '<div class="col-md-6 well">';
output += '<div class="col-md-7">';
output += '<h5>' + val.productName + '</h5>';
output += '<p>' + val.productPrice + '</p>'
output += '<p>' + val.ProductDiscount + '</p>'
output += '</div>';
output += '</div>';
if(count%2 == 0) {
output += '</div><div class="row">'
}
count++;
}
});
output += '</div>';
$('#show_results').html(output);
});
});
});
您將JSON文件放在文件夾層次結構中的位置? – squiroid
@squiroid我把劇本和在同一文件夾中的JSON檔案。根文件夾 –
那麼爲什麼不通過你給的URL訪問? http://www.my-site.com/index.php/admin_cotrol/shop_list.json – squiroid