如何从REST服务获取JSON数据

时间:2014-04-01 07:35:42

标签: jquery ajax rest service

您正在使用restfull服务并使用jquery传递JSON数据。 我能够点击URL,如何获取我在方法中从JQuery传递的JSON数据。
我的休息服务是

        [OperationContract]
    [WebInvoke(Method = "POST",
        BodyStyle = WebMessageBodyStyle.Wrapped,
        RequestFormat = WebMessageFormat.Json,
        ResponseFormat = WebMessageFormat.Json,
        UriTemplate = "InsertIntoDB/{jsonString}")]
    string InsertIntoDB( string jsonString);


我打电话给上述服务:

url = "http://localhost:54552/OfflineService.svc/InsertIntoDB/SomeRandomString";

    $.ajax({
        type: "POST",
        data: JSON.stringify(EmployeeData),
        url: url,
        contentType: "application/json; charset=utf-8",
        dataType: "json",
        processData: true,
        success: function (data) {
            alert("success..." + data);
        },
        error: function (xhr) {
            alert(xhr.responseText);
        }
    }
    );

EmployeeData是一个包含员工数据的数组,

我可以点击该服务,但我想知道如何获得EmployeeData。

0 个答案:

没有答案