Ajax response inside a div
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');
}
});
success: function(server_response) {
$(".result").html(server_response);
}
<div class="result"></div> // result is the class
The selector should be .result
not #result