Jquery Ajax WCF参数

And*_*ers 2 asp.net ajax wcf jquery

在传递两个参数时,我无法从jquery获得WCF调用.如果我稍微更改代码以通过一件事就可以了.

Javascript:

 $.ajax({
    type: "POST", //GET or POST or PUT or DELETE verb
    url: "/Services/JobNumberService.svc/GetActiveJobNumberByCustomerOrJointBilling", // Location of the service
    data: '{"customerId": "' + customerId + '", "departmentId": "' + departmentId + '"}', //Data sent to server
    contentType: "application/json; charset=utf-8", // content type sent to server
    dataType: "json", //Expected data format from server
    processdata: true, //True or False
    success: function (msg) {//On Successfull service call
        fillDropDownFromLookupList(msg, jobNumberDropDownId);

        prependItemToDropDown('', 'NONE', jobNumberDropDownId); //Add blank item to top of list
    },
    error: ServiceFailed// When Service call fails
});
Run Code Online (Sandbox Code Playgroud)

服务签名:

public LookupList GetActiveJobNumberByCustomerOrJointBilling(int customerId, int departmentId)
Run Code Online (Sandbox Code Playgroud)

它必须与我如何格式化传入的json有关.它根据JSONLint有效,但可能不是.net期望的.

赞赏的想法.

编辑

这是我在回复中得到的

HTTP/1.1 500 Internal Server Error
Server: ASP.NET Development Server/11.0.0.0
Date: Thu, 28 Feb 2013 20:30:17 GMT
X-AspNet-Version: 4.0.30319
Cache-Control: private
Content-Length: 0
Connection: Close
Run Code Online (Sandbox Code Playgroud)

哦,我还试图关闭我的代码调试,以追踪错误是什么,但我没有看到由于某种原因的任何异常.

Mus*_*usa 5

您的服务将int值作为参数,但您要将其发送给字符串.如果是customerIddepartmentId数字,您需要删除它们周围的引号,以便它们被解释为这样.

'{"customerId": ' + customerId + ', "departmentId": ' + departmentId + '}'
Run Code Online (Sandbox Code Playgroud)