我已经看了一段时间了,看不到问题出在哪里。任何帮助是极大的赞赏。

[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":"Invalid web service call, missing value for parameter: \u0027force\u0027.","StackTrace":"

最佳答案

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

使用提琴手或类似工具来检查网络流量,并查看实际发送到您的Web服务的内容。

09-25 18:19
查看更多