Jquery Ajax WCF 参数

标签 jquery asp.net ajax wcf

在传递两个参数时,我无法从 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
});

服务签名:

public LookupList GetActiveJobNumberByCustomerOrJointBilling(int customerId, int departmentId)

这一定与我格式化传入的 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

O,我还尝试关闭代码调试来跟踪错误是什么,但由于某种原因我没有看到任何异常。

最佳答案

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

'{"customerId": ' + customerId + ', "departmentId": ' + departmentId + '}'

关于Jquery Ajax WCF 参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15145318/

相关文章:

c# - 如何测试.net web应用程序中哪个方法执行需要多长时间

asp.net - 谷歌地图未加载到容器中

php - Symfony2 : Prevent duplicate in database with form Many to One

javascript - 如何获取动态创建的选择框的值

jquery - 如何在asp.net中使用JSON和JQuery从WebMethod返回DataTable?

javascript - 当 iframe 完全加载时触发函数

javascript - 如何获取在没有页面加载的情况下创建的 JS cookie?

C# EF Deep Lambda 非重复计数查询

Jquery ajax json 获取由 Flask Web 框架传递的调用 - 调用失败

javascript - HTML/CSS/JS 中的几何图案