1
我在调用http处理程序中的webmethod时出现问题。该文件的jquery.js在一些随机的地方打开,并给出提示 “无效参数”jquery 1.5 ajax调用给处理程序中的webmethod提供无效参数
代码如下:
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中的“无效参数” –