I am updating the database whenever a user clicks the like button. The update is successfully done but the problem is in updating the new fetched value from the database.
Control Function on which ajax is posting data :
public function plusrepo()
{
if($this->input->is_ajax_request())
{
$this->load->model('themodel');
$rep['updated'] = $this->themodel->addrepo($this->input->post('resid'));
echo $rep['updated'][0]." <span>Reputation</span>";
}
}
This is how i am selecting from table and returning the result array.
$this->db->select('repo');
$this->db->from('restaurants');
$this->db->where('id', $id);
$result = $this->db->get();
return $result->result_array();
My Ajax function on success does this :
success: function(){
alert("Success");
$(this).addClass('.up_arrow').removeClass('.up_arrowed');
$('.rep_count').html(data);
}
What is wrong? I'm confused.
Edited This is the complete function for ajax
$('.up_arrow').each(function() {
$(this).click(function(event) {
event.preventDefault();
var resid = $(this).attr('name');
var post_data = {
'resid' : resid,
'<?php echo $this->security->get_csrf_token_name(); ?>' : '<?php echo $this->security->get_csrf_hash(); ?>'
};
if(resid){
$.ajax({
type: 'POST',
url: "/ci_theyaw/restaurants/plusrepo",
data: post_data,
success: function(data){
console.log(data);
// alert(data);
// $(this).addClass('.up_arrow').removeClass('.up_arrowed');
// $('.rep_count').html(data);
},
error: function (xhr, ajaxOptions, thrownError) {
alert(xhr.status);
console.log(xhr.responseText);
alert(thrownError);
}
});
}
});
});
.successhandler gets called (ie youralert()gets called)? Or does your controllerechothe right data? It is best to isolate the problem.POST http://localhost/ci_theyaw/restaurants/plusrepo jquery.js:8526 send jquery.js:8526 jQuery.extend.ajax jquery.js:7978 (anonymous function) restaurants:456 jQuery.event.dispatch jquery.js:3074 elemData.handle