The problem is that you have mixed arguments of Ajax success
handler. First goes data
which your script gives back, then goes textStatus
. Theoretically it can be “timeout”, “error”, “notmodified”, “success” or “parsererror”. However, in success
textStatus will always be successful. But if you need to add alert
on error you can add error
handler. And yes, change selector in $(“#result”) to class. So corrected code may look like this:
$.ajax({
type: "POST",
url: "<?php echo base_url(); ?>contents/hello",
data: "id=" + a_href,
success: function(data, textStatus) {
$(".result").html(data);
},
error: function() {
alert('Not OKay');
}
});