【问题标题】:Invalid JSON primitive JQUERY无效的 JSON 原语 JQUERY
【发布时间】:2020-12-29 11:14:22
【问题描述】:

我正在使用这个函数从我的数据库中获取数据,使用 asp.net 和 c# 中的 Web 服务 这是我的功能

 function test(MsId) {
                    var options = { weekday: 'long', year: 'numeric', month: 'long', day: 'numeric' };
                    $(document).ready(function () {
                        $.ajax({
                            url: "/web_service/Services.asmx/GetData",
                            type: "GET",
                            dataType: "json",
                            data: {
                                'MsId': MsId
                            },
                            contentType: "application/Json; Charset= Utf-8",
                            success: function (data) {
                                var list = "";
                                $.each(data.d[0][0], function (index, item) {
                                    list += "<div class='active'><div class='direct-chat-infos'><span class='direct-chat-name float-left'>" + item.CompleteName + "</span>&nbsp;&nbsp;" + item.Status_Status + "</div><span class='direct-chat-timestamp float-left text-sm'>" + new Date(parseInt(item.Status_Date.substr(6))) + "</span><br /></div>";
                                });
                                $("#List").html(list);
                            },
                            error: function (response) {
                                alert(response);
                            }
                        });
                    });
                }

但她给了我这个错误,我正在使用加密 id(图片) enter image description here

【问题讨论】:

  • 我们无法知道您的服务器为何返回该错误。
  • @Taplar 我想我正在使用 id 解密?
  • 完全不知道。我们不知道该端点是如何实现的。

标签: jquery asp.net ajax


【解决方案1】:

$.ajax 本身不会将数据转换为 json,你需要这样做

改变

data: { 'MsId': MsId },

data: JSON.stringify({ 'MsId': MsId }),

另请注意,我从未见过"application/json" 中使用大写字母

【讨论】:

  • {"Message":"无效的 Web 服务调用,缺少参数值:\u0027MsId\u0027。","StackTrace":" 在 System.Web.Script.Services.WebServiceMethodData.CallMethod(Object目标,IDictionary2 parameters)\r\n at System.Web.Script.Services.WebServiceMethodData.CallMethodFromRawParams(Object target, IDictionary2 个参数)\r\n 在 System.Web.Script.Services.RestHandler
  • 那么你是如何调用函数的呢?在发出请求之前检查 Msld 是什么
  • iam 像这样调用我的函数 test(Id);
  • OK ...id 是否已定义且有效值?您的错误意味着没有发送任何值
  • 谢谢,我认为问题出在加密的 id 上,因为我发送的 id 没有解密工作正常 :(
猜你喜欢
  • 1970-01-01
  • 2014-02-01
  • 2015-06-13
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-08-24
  • 2020-07-31
相关资源
最近更新 更多