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.
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);
  } 
});         
                        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. :)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With