Error in jQuery ajax method and the page get refresh
ajax, codeigniter, jquery
Solution
Try using `preventDefault`:
$('.cn').click(function (e) {
e.preventDefault();
var pic_id = $(this).attr('href');
console.log(pic_id);
//alert(pic_id);
$.ajax({
type : "POST",
url : "<?php echo base_url();?>anda/coins",
async : false,
data : "pic_id=" + pic_id,
dataType : 'json',
success : function (data) {
//alert(data);
$('.cn_point').html(data.id);
}
});
});
Problem
``` $('.cn').click(function() { var pic_id = $(this).attr('href'); console.log(pic_id); //alert(pic_id); $.ajax({ type: "POST", url: "<?php echo base_url();?>anda/coins", async: false, data: "pic_id="+pic_id, dataType: 'json', success: function(data){ //alert(data); $('.cn_point').html(data.id); } }); }); ``` I got the call back value and showing on but page gets refresh and value of span hide. is there anybody can help me ?I m unable to find my mistake .