【发布时间】:2017-05-25 17:52:25
【问题描述】:
我正在尝试使用 CodeIgniter 和 $.getJson 在脚本的同一文件夹中加载 Json 文件。
我已经尝试在我的站点根目录和应用程序文件夹中更改 .htaccess 内容,将加载路径更改为
.$getJson("<?php echo base_url...")
没有任何效果。它总是显示相同的错误:
jquery.min.js:4 获取 http://www.my-site.com/index.php/admin_cotrol/shop_list.json 404(未找到)
这是我的脚本:
$(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 我将脚本和 json 存档放在同一个文件夹中。根文件夹
-
那为什么无法通过您提供的 URL 访问它? my-site.com/index.php/admin_cotrol/shop_list.json
-
我也进不去
-
使用基本路径访问文件
<?php echo base_url()/folder/shop_list.json ?>
标签: php jquery json ajax codeigniter