Reputation: 11
i'm new to codeigniter i can't not get data from the controller using the ajax request i think i do mistake in writing the url of the controller function in ajax call
here is the code of my ajax call
$(document).ready(function(){
$("#fname").focusout(function(){
// alert();
$.ajax({
url: "<?php echo base_url();?>/proposal/ajax_load",
type: 'POST',
success: function(result){
$("#div1").html(result);
}
});
});
});
Here is my controller
class Proposal extends CI_Controller {
public function ajax_load()
{
return ("Hello");
}
}
Upvotes: 1
Views: 166
Reputation: 3714
in ajax_load() - Should be echo not return if you're getting a response via ajax.
Upvotes: 1
Reputation: 8288
You are confuse between the meaning of [Return, Echo]
in PHP,
echo — Output one or more strings
return returns program control to the calling module. Execution resumes at the expression following the called module's invocation.
and as long as the Ajax response callback is reading a server response [output], you must send an output to the server.
public function ajax_load()
{
echo "Hello";
}
Further reading :-
What is the difference between PHP echo and PHP return in plain English?
Difference between php echo and return in terms of a jQuery ajax call
a short and simple answer
Upvotes: 2