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中的「無效參數」 –