【问题标题】:jquery 1.5 ajax call giving invalid argument for webmethod in a handlerjquery 1.5 ajax 调用在处理程序中为 webmethod 提供无效参数
【发布时间】: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


【解决方案1】:

嗯,找不到任何解决方案或导致这种行为的原因!

在页面中保留相同的 webmethod 并使其正常工作。因此添加了仅在进程请求中处理 ajax 调用的逻辑。像魅力一样工作。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2020-01-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-12-14
    相关资源
    最近更新 更多