jquery - 无效的 Web 服务调用,缺少参数值

标签 jquery asp.net ajax webmethod

我看了这个问题有一段时间了,不知道问题出在哪里。非常感谢任何帮助。

[WebMethod(true)]
[ScriptMethod(UseHttpGet = true, ResponseFormat = ResponseFormat.Json)]
public static string neighbourhoodTeam(string force, string neighbourhood) 
{
    //StreamManager streamMan = new StreamManager();
    //return streamMan.StreamManagerUrlHandler("http://policeapi2.rkh.co.uk/api/" + force + "%2F" + neighbourhood + "%2F" + "people");
    return neighbourhood + force;
}

jQuery:

function getOfficers(force, neighbourhood) {
    $.ajax({
        type: "GET",
        contentType: "application/json; charset=utf-8",
        url: "../police/crimerequest.aspx/neighbourhoodTeam",
        data: JSON.stringify({ "force": force, "neighbourhood": neighbourhood }),
        dataType: "json",
        success: function (data) {
            var results = $.parseJSON(data.d);
            $.each(results, function (i) {
                businessCards.push(generateOfficerBusinessCard(
                            results[i].name,
                            results[i].rank,
                            results[i].contact_details.mobile,
                            results[i].contact_details.tel,
                            results[i].contact_details.email))
            });
            PoliceApp.businessCardsPlaceHolder.html(businessCards.toString());
        },
        error: function (xhr, ajaxOptions, thrownError) {
            alert(xhr.status);
            alert(thrownError);
            alert(xhr.responseText);
            return false;
        }
    });
}

我得到:{"Message":"无效的 Web 服务调用,缺少参数值:\u0027force\u0027。","StackTrace":"

最佳答案

尝试在ajax参数中使用processData: false发送。默认情况下,jQuery 将再次进行字符串化。

使用 fiddler 或类似工具检查网络流量并查看实际发送到您的网络服务的内容。

关于jquery - 无效的 Web 服务调用,缺少参数值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6471759/

相关文章:

javascript - 获取 <div> 标签的值

javascript - bootstrapValidator ajax请求,防止提交后关闭 Bootstrap 模式

javascript - Web SQL 数据库 - 执行异步调用并继续

javascript - 如何使用 javascript/jquery 从 url 中提取文件名?

php - 显示更新成功警报但无法单击警报,并且数据库未更新

Linux 上的 ASP.Net

ASP.NET session 状态性能基准

javascript - 在继续 AJAX post 之前检查验证

asp.net - IE兼容模式问题

javascript - ajax调用后仅在正确的选项卡中显示信息