我正在尝试进行 Ajax 调用,但它导致页面加载这是我的 jquery 代码
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;
}
这是我的 AjaxCallHandler.aspx.cs c# 代码
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);
}
我不知道为什么这件事会导致页面加载。我是 jquery AJAX 的新手,但是当我尝试使用 javascript AJAX 时,它在没有任何页面加载的情况下工作正常。