简体   繁体   中英

Failed to load resource: the server responded with a status of 500, Codeigniter project

I'm trying to send a call using ajax but in Chrome it is rising error but in firefox there is no error. But still it can't calling the method. THis append shows 7 divs, but some div gets loaded but some of div keeps loading and console shows error 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));
}

Here is view part

$('#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>');

Here is Ajax function

/* 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");                  
            }
        }
});
}

I suspect this line

url="<?php echo "/./home-recent-articles-filter-cat/";?>"+category+"/"+limit+"/";

Codeigniter URL does not look like this. It contains at least 3 parameters on it(unless index function)

  1. base URL
  2. controller name
  3. method name

So it should be something like this

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

Make sure these are loaded

  1. URL helper
  2. short_tag=On in PHP.ini

Check these

  1. Set up the base URL in codeigniter

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM