JQuery AJAX returns error 500 despite successful server-side execution

I ran into a problem with codeigniter and jQuery Ajax Post.

My javscript

        $('.remove').click(function(){
        var category=event.target.id;
        var id=$('input[name=article_id]').val();
        var p={};
        p['id']=id;

        $.ajax({
            type: "POST",
            url: "/backend.php/blog/removeCategories",
            async:true,
            cache:false,
            data: {id: id, category: category }
            }).done(function(msg){
                jQuery('#category_list').load('/backend.php/blog/refreshCategories/',p,function(str){});
            });

My codeigniter controller

 function removeCategories(){
        $id=$_POST['id'];
        $category_id=$_POST['category'];

        $this->article->removeCategory($category_id,$id);
    }

I can not get the ajax function to work, because there is always a 500 error received from the server. Although firebug returns that there was an error loading resources, the removeCategories function was executed anyway.

+5
source share
3 answers

Your mistake may be in the model. Use the chrome dev toolkit to find out what the content of the returned page is. HTTP CODE 500means a server error, usually due to a syntax problem inside PHP.

, - success: error:. , .

backend.php/ index.php?

- .load() html , success: function(data){} . , ajax error() success() .

+3

, , data.

$.ajax({
            type: "POST",
            url: "/backend.php/blog/removeCategories",
            async:true,
            cache:false,
            data: {"id": id, "category": category }
            }).done(function(msg){
                jQuery('#category_list').load('/backend.php/blog/refreshCategories/',p,function(str){});
            });

, .

+6

Codeigniter, csrf_protection config, Error 500!

, csrf.

:

$.ajax({
          type: "POST",
          url: "http://example.com",
          data: {
                 '<?php echo $this->security->get_csrf_token_name(); ?>' : 
                 '<?php echo $this->security->get_csrf_hash(); ?>'
                }
       });
+2

All Articles