weixin_33737774 2012-11-17 23:21 采纳率: 0%
浏览 43

jQuery + AJAX + c#导致页面加载

i'm trying to make an Ajax call but its causing page load Here is my jquery code

    var ajaxUrl = "AjaxCallHandler.aspx";
function _init_Chart() {

$.ajax({
    type: "GET",        //GET or POST or PUT or DELETE verb
    url: ajaxUrl,       // Location of the service
    data: "OpCode=GetCallAverageReportForGraph&Parms=DeptId^17~Month^10~Year^2012",         //Data sent to server
    contentType: "",    // content type sent to server
    dataType: "string",     //Expected data format from server
    processdata: true,  //True or False
    success: function (responseString) {//On Successful service call
        alert(responseString);
    }
});

return false;
}

And here is my AjaxCallHandler.aspx.cs c# code

protected void Page_Load(object sender, EventArgs e)
{
    string responseMessage = "";
    string status = "SUCCESS";
    try
    {
        if (Request.QueryString["OpCode"] == null)
        {
            throw new Exception("Invalid Request, OpCode missing.");
        }
        string operationRequested = Request.QueryString["OpCode"];
        string Params = Request.QueryString["Parms"];
        switch (operationRequested)
        {
            case "GetCallAverageReportForGraph":
                responseMessage = GetCallAverageReportForGraph(Params);
                break;
            case "GetCallAverageReportDetails":
                responseMessage = GetCallAverageReportDetails(Params);
                break;
        }
    }
    catch (Exception exp)
    {
        status = "EXCEPTION";
        responseMessage = exp.Message;
    }
    Response.ClearContent();
    Response.ClearHeaders();
    Response.Write(responseMessage);
}

I dont know why this thing is causing a page load.i'm new to jquery AJAX but when i tried this with javascript AJAX it was working fine without any page load.

  • 写回答

1条回答 默认 最新

  • weixin_33705053 2012-11-17 23:33
    关注

    I'm assuming that is the code behind for your AjaxCallHandler.aspx?

    If so, your AJAX call is essentially just loading the results of that page just like you would if you were hitting it with a browser window (i.e. a GET).

    Most of the time when you want to do an AJAX request, you would be calling it against an MVC function that returns a JSONResult ActionResult or a Web Service (.asmx) for example.

    Since you're just hitting a regular web page, it will always do a Page_Load event on that page's code behind.

    评论

报告相同问题?

悬赏问题

  • ¥20 sub地址DHCP问题
  • ¥15 delta降尺度计算的一些细节,有偿
  • ¥15 Arduino红外遥控代码有问题
  • ¥15 数值计算离散正交多项式
  • ¥30 数值计算均差系数编程
  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大