I am encountering 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's controller
function removeCategories(){
$id=$_POST['id'];
$category_id=$_POST['category'];
$this->article->removeCategory($category_id,$id);
}
I can't get the ajax function to work because there is always an error 500 received from the server. Although, firebug returns that there is an error loading the resources, the function removeCategories was executed anyways.
The 500 Internal Server Error is a very general HTTP status code. It means something has gone wrong on the website and webserver is unable to specify what exactly, thus failing in fulfilling the request made by the client.
The 500 Internal Server error could be caused by an error during the execution of any policy within Edge or by an error on the target/backend server. The HTTP status code 500 is a generic error response. It means that the server encountered an unexpected condition that prevented it from fulfilling the request.
Make sure your data is being passed properly by making the following changes to the data
option.
$.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){});
});
The way you have it coded, the key of each key value pair is being set to the variable's value.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With