【问题标题】:WCF Service Not Parsing jsonP Parameters correctlyWCF 服务未正确解析 jsonP 参数
【发布时间】:2016-06-24 13:52:07
【问题描述】:

我正在发送这样的电话:

$.ajax({
            url: myURL+functionName,
            contentType: "application/json; charset=utf-8", //also tried application/javascript
            cache: false,
            dataType: "jsonp",
            data: parameter,
            success:function(response){
                alert("great success!");
            },
            error:function(error) {alert("boo-urns");}

这很好,一切看起来都应该如此。参数对象的值如下:

{ac:"a8d8e6ef-5907-4978-11cf-39add52b996c",
date:"20160626",
deviceId:"W-eXXX9680-13X3-9317-f1b3-eXXXXe50",
komponenten:Array[5],
menu_kf_nr:1,
mz_nr:"3",
pt_kf_nr:1,
pt_nr:"311701",
sessionId:"b22bXXX6-20XX-4XXX-9ed6-0dXXb297"}

这是服务器端方法:

public bool functionName(string ac, string date, string deviceId, List<komponenten> komponenten, int? menu_kf_nr, string mz_nr, int pt_kf_nr, string pt_nr, string sessionId) {
    //do stuff with the data 

}

然后在服务器端,虽然我的参数如下:

ac  "a8d8e6ef-5907-4978-11cf-39add52b996c"  string
date    "20160626"  string
deviceId    null    string
komponenten null    System.Collections.Generic.List<kompnenten>
menu_kf_nr  null    int?
mz_nr   "3" string
pt_kf_nr    1   int
pt_nr   "311701"    string
sessionId   null    string

谁能告诉我需要在哪里查看才能消除空值?

提前致谢

【问题讨论】:

    标签: javascript c# .net web-services wcf


    【解决方案1】:

    您应该在 aJax 调用中单独传递参数,此外,C# 端可能期望接收 JSON 数据。

    看看here,看看如何在 aJax 调用中传递多个参数。

    注意接受答案的第二部分,使用JSON.Stringify

    【讨论】:

      猜你喜欢
      • 2014-08-20
      • 2017-05-13
      • 1970-01-01
      • 1970-01-01
      • 2011-05-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多