cabaret cabaret - 1 month ago 12
jQuery Question

CodeIgniter/jQuery - Ajax call returns full html page instead of my echo

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.

Answer

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);
  } 
});