codeIgniter / jQuery的 - Ajax调用返回我的回声完整的HTML页面,而不是我的、回声、而不是、完整

2023-09-10 19:12:45 作者:橱窗下的月光光。

在我看来,我有一个Ajax调用:

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

        });

在我的规划控制器get_cal功能:

the get_cal function in my Planner controller:

function get_cal()
{
    echo "dinosaurs";
}

不过,而不是返回恐龙,它返回一个完整的HTML页面。我想不通为什么。思考?非常感谢。

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