weixin_33725239 2014-06-04 09:36 采纳率: 0%
浏览 28

Ajax不进行函数调用

I have ajax function as:

function LoadTeacherObservationData(_CategoryID, _SearchText) {
        alert("In here");
        alert(_CategoryID);
        alert(_SearchText);
        flag = 1;
        $.ajax({
            url: "PP/getTeacherObservationData",
        data: {
        'CategoryID': _CategoryID,
        'SearchText': _SearchText
        },
    dataType: "json",
        type: 'POST',
    cache:false,
    success: function (data) {
        OnlebelChange(_CategoryID);
        $('#hdnCategoryID').val(_CategoryID);

        $("#lvTeacherData").kendoListView({
            dataSource: data,
            dataBound: function(e) {
                if(this.dataSource.data().length == 0){
                    //custom logic
                    $("#lvTeacherData").append("<h4>&nbsp;&nbsp;No record found.</h4>");

                }},
            template: kendo.template($("#lvTeacherData_Template").html())
        });
    },
    error: function () {
        alert("error in click");
    }
    });
    }

I have made sure that function is getting called with correct parameters as i have checked it through alert box.

My problem is its not getting rendered to:

PP/getTeacherObservationData as i have mentioned in URL.

PP is my controller and getTeacherObservationData is my function.

I have written that function as follows:

public JsonResult getTeacherObservationData(string CategoryID, string SearchText)
        {
            try
            {
                if (CategoryID == "1")
                    return Json(new TeacherObservation().ScheduledObserVations(SearchText));
                if (CategoryID == "2")
                    return Json(new TeacherObservation().InProcessObservations(SearchText));
                if (CategoryID == "3")
                   return Json(new TeacherObservation().CompletedObservations(SearchText));

                return Json(new List<TeacherObservation>());
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }

Instead of calling this function ajax function code goes in error block and gives me alert as: error in click

What can be the problem??

Please help me.

I want to make function call through ajax.

Using MVC4.

  • 写回答

2条回答 默认 最新

  • weixin_33722405 2014-06-04 09:43
    关注

    I don't know what PHP Framework you are using, but normally you can't just return a value to an AJAX call, you have to ouput it somehow to send it back to the caller. Try to use echo or print instead of return.

    To prevent further rendering (if any), you should somehow end the script after it has echoed your specified JSON.

    You should also check for the output that is rendered in firebug or similar consoles to see if you get a plain JSON (which you obvoiously expect) or some HTML wrapped content which is rendered by your php framework and connot be parsed.

    评论

报告相同问题?

悬赏问题

  • ¥15 如何提取csv文件中需要的列,将其整合为一篇完整文档,并进行jieba分词(语言-python)
  • ¥15 MapReduce结果输出到HBase,一直连接不上MySQL
  • ¥15 扩散模型sd.webui使用时报错“Nonetype”
  • ¥15 stm32流水灯+呼吸灯+外部中断按键
  • ¥15 将二维数组,按照假设的规定,如0/1/0 == "4",把对应列位置写成一个字符并打印输出该字符
  • ¥15 NX MCD仿真与博途通讯不了啥情况
  • ¥15 win11家庭中文版安装docker遇到Hyper-V启用失败解决办法整理
  • ¥15 gradio的web端页面格式不对的问题
  • ¥15 求大家看看Nonce如何配置
  • ¥15 Matlab怎么求解含参的二重积分?