【发布时间】:2019-03-19 11:28:46
【问题描述】:
我正在尝试使用 ajax 发送呼叫,但在 Chrome 中出现上升错误,但在 firefox 中没有错误。但它仍然无法调用该方法。 此附加显示 7 个 div,但一些 div 被加载,但一些 div 继续加载,控制台显示错误 500
//get recent posts via ajax controller class
public function get_recent_articles($cr_post_id,$category,$limit,$offset)
{
$recent_post=$this->Post_model->get_recent_articles($cr_post_id,$category,$limit,$offset);
return $this->output
->set_content_type('application/json')
->set_status_header(200)
->set_output(json_encode($recent_post));
}
这里是视图部分
$('#recent_post_cat_2').show();
$('#recent_post_cat_2').append('<div id="recent_post_cat_2_preloader" class="col-md-12 col-sm-12 text-center" style="vertical-align:middle;padding:15px 0px;"><i class="fa fa-spinner fa-spin" style="font-size:24px"></i></div>');
这里是Ajax函数
/* START - get_recent_articles*/
function get_recent_articles(category,div_id,limit)
{
//prepare url
url="<?php echo "/./home-recent-articles-filter-cat/";?>"+category+"/"+limit+"/"; $.ajax({
url: url,
type: 'GET',
dataType: "json",
crossDomain: true,
success: function(data){
// console.log(JSON.stringify(data));
if(data.status=="success")
{
prepared_posts_data=prepare_cards(category,data.data,3);
$(div_id+'_preloader').remove();
$(div_id).append(prepared_posts_data);
$(div_id).show();
var myLazyLoad = new LazyLoad({
threshold: 50,
callback_load: function(e) {
// console.log($(e).attr("data-original") + " loaded" );
}
});
}
else{
console.log("no posts available");
}
}
});
}
【问题讨论】:
-
关键点:一些 div 很容易加载,但有时只有加载器可以工作。
-
你的 $offset 参数在哪里?在 ajax 网址中
-
我没有,实际上是新手。那是已经开发的项目。
-
然后将其作为默认参数传递,即 $offset=''
标签: php json ajax codeigniter