CodeIgniter/jQuery - Ajax call returns full html page instead of my echo
14,411
Solution 1
I solved this by using a leading slash as suggested in the comments to my question.
$.ajax({
type: "POST",
url: "/planner/get_cal",
dataType: "text",
data: {current_month: current_month},
success: function(msg){
alert(msg);
}
});
Solution 2
You can also get it by adding exit after echo in your php file like below:
function get_cal()
{
echo "dinosaurs";exit;
}
It will work. :)
Related videos on Youtube
Author by
Joris Ooms
Updated on June 04, 2022Comments
-
Joris Ooms almost 2 years
In my view I have an ajax call:
$(".previous").click(function() { $.ajax({ type: "POST", url: "planner/get_cal", data: {current_month: current_month}, success: function(msg){ alert(msg); } });
the get_cal function in my Planner controller:
function get_cal() { echo "dinosaurs"; }
However, instead of returning "dinosaurs", it returns a full HTML page. I can't figure out why. Thoughts? Thanks a lot.
-
sleepisforthewebless about 13 yearsHave you tried adding a leading slash?
url: "/planner/get_cal",
-
David Houde about 13 yearsI second the leading / -- Otherwise things look just fine, and this shouldn't be happening.
-
-
Scaramouche over 5 yearsthis works right now. I changed
exit
forreturn
though, :)