【发布时间】:2011-11-30 16:36:25
【问题描述】:
我在我的 http 处理程序中调用 webmethod 时遇到问题。 jquery.js 文件在某个随机位置打开并提示“无效参数”
代码如下:
JS:
var src = "MyHandler.axd";
var id = "1234566";
$.ajax({
type: "GET",
contentType: "application/json; charset=utf-8",
url: src + "/MyMethod?key=" + id,
success: function (msgObj) {
var msg = msgObj.d;
},
error: function (e) {
alert("Error");
}
});
C#
[System.Web.Services.WebMethod(EnableSession = true)]
[System.Web.Script.Services.ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string MyMethod(string key)
{
return someLogic;
}
因此,为 ajax 调用调用了 ProcessRequest 方法。
甚至尝试过以下操作 从 c# 代码中删除了 httpget 和 responseformat。
JS
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: src + "/MyMethod",
data: "{ 'key':'"+ id +"'}",
dataType: "json",
success: function (msgObj) {
debugger;
var msg = msgObj.d;
},
error: function (e) {
debugger;
}
});
【问题讨论】:
-
哪个 jquery 文件抛出异常?你引用了哪些 jquery 文件?
-
Jeff,它的 jquery-1.5.min.js,在某个随机的地方它在 VS2010 中显示“无效参数”
标签: c# jquery asp.net ajax webmethod