I’m using jQuery to send an ajax request and even though it’s triggering ‘success’ the alert ‘msg’ is empty. The alert pop-up comes us, but it’s empty.
I’ve used nearly identical function elsewhere on the same page/controller without issue. Thanks for any insights on this.
Jquery:
$('#inputScale').change(function() {
$.ajax({
type : 'POST',
url : '<?php echo site_url('resume/change_scale'); ?>',
data: {
resume_id : '<?php echo $this->session->userdata('resume_id'); ?>',
inputScale: $('#inputScale').val()
},
success : function(msg){
alert(msg);
},
error: function(){
alert('failure');
}
});
});
PHP excerpt:
public function change_scale()
{
return "TEST";
}
When using jQuery’s .ajax() method, it calls a page and on success, allows you to handle the output (i.e. what would be displayed on that page if you called it directly in your browser).
In your case, you are just doing a return from the function which won’t work as you expect. Try this instead:
When the function is done echoing, it sends TEST back to jQuery which is handled in your
success: function(msg){ alert(msg); }section.