这是我的问题:
我正在制作一个Ajax来调用Handler。如果我执行GET,这可行,但如果我执行POST,则会收到网络错误404。这怎么可能?
var jsondata = { zip: myzip, country: mycountry }; // this contains data
$.ajax({
url: "/upstracker/timeintransit/",
data: jsondata,
dataType: "json",
type: "POST", // This fails - giving 404 error.
// type: "GET", // This works
async: false,
success: function (data) {
console.log(data);
},
error: function (jqXHR, textStatus, errorThrown) {
console.log(jqXHR);
}
});
处理程序:
Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
// All logic to create data - ServicesEstimatedDatelist Contains List of required data
Dim jSearializer As System.Web.Script.Serialization.JavaScriptSerializer = New System.Web.Script.Serialization.JavaScriptSerializer()
context.Response.ContentType = "application/json"
context.Response.ContentEncoding = Encoding.UTF8
context.Response.Write(jSearializer.Serialize(ServicesEstimatedDatelist))
End Sub
Handler的重写链接在重写规则文件中设置,该文件正在运行。
答案 0 :(得分:0)
因此我无法执行 POST 的原因是:
在处理程序的webconfig中添加重写规则时,我将其限制为 GET :
示例:
<add name="UPSTime_in_Transit_tracker" verb="GET" path="/upstracker/timeintransit" type="NameOfHandler"/>
<强>对战强>
<add name="UPSTime_in_Transit_tracker" verb="*" path="/upstracker/timeintransit" type="NameOfHandler"/>