【问题标题】:Failed to load resource: the server responded with a status of 500, Codeigniter project加载资源失败:服务器响应状态为 500,Codeigniter 项目
【发布时间】: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


【解决方案1】:

我怀疑这条线

url="&lt;?php echo "/./home-recent-articles-filter-cat/";?&gt;"+category+"/"+limit+"/";

Codeigniter URL 看起来不像这样。它至少包含3个参数(除非index函数)

  1. 基本网址
  2. 控制器名称
  3. 方法名称

所以应该是这样的

url = <?= base_url(); ?>.'controller_name/get_recent_articles'

确保这些已加载

  1. 网址助手
  2. short_tag=On 在 PHP.ini 中

检查这些

  1. Set up the base URL in codeigniter

【讨论】:

  • 我猜这是为了通过 url 传递 para。
  • 是的,您可以在 URL 旁边添加那些,例如 url = &lt;?= base_url(); ?&gt;.'controller_name/get_recent_articles/'.5/10/2/0
  • home-recent-articles-filter-cat 是视图文件的名称
  • 使用正确的控制器名称。请参阅 codeigniter 教程。
猜你喜欢
  • 2018-01-22
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-04-10
  • 1970-01-01
  • 1970-01-01
  • 2017-10-11
  • 2017-11-14
相关资源
最近更新 更多