我需要從jQuery調用處理程序(ashx)文件以在運行時獲取一些數據。 我jQuery的功能是這樣的:從jQuery調用處理程序不起作用
var pID = 3;
var tID = 6;
$("#Button1").click(function() {
var urlToHandler = "Controller/TestHandler.ashx";
$.ajax({
type: "POST",
url: urlToHandler,
data: "{'pID':'" + pID + "', 'tID':'" + tID + "'}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function(msg) {
alert(msg);
}
});
});
我的處理代碼:
<%@ WebHandler Language="C#" Class="TestHandler" %>
using System;
using System.Web;
public class TestHandler : IHttpHandler
{
public void ProcessRequest (HttpContext context)
{
String pID = context.Request.Params["pID"];
String tID = context.Request.Params["tID"];
context.Response.ContentType = "text/plain";
context.Response.Write(pID + " " + tID);
}
public bool IsReusable
{
get {
return false;
}
}
}
的問題是執行代碼沒有達到的處理程序代碼。 我可以從處理程序文件所在的相同目錄中的相同jQuery函數調用其他Web窗體(aspx)文件。所以這不是任何路徑問題。
我是這個處理程序文件概念的新手。我GOOGLE了很多,但在我的代碼中找不到任何錯誤。
小提琴手說什麼? (或螢火蟲?) – aquinas 2012-04-26 04:39:27
它沒有顯示任何錯誤。 – 2012-04-26 04:43:22
那麼,它會返回200,成功嗎? – aquinas 2012-04-26 04:45:49