weixin_33724570 2017-04-13 10:35 采纳率: 0%
浏览 34

缺少参数名称:adi [重复]

This question already has an answer here:
                </div>
            </div>
                    <div class="grid--cell mb0 mt4">
                        <a href="/questions/18618748/missing-parameter-in-ajax-post-to-asmx" dir="ltr">Missing parameter in Ajax post to Asmx</a>
                            <span class="question-originals-answer-count">
                                (1 answer)
                            </span>
                    </div>
            <div class="grid--cell mb0 mt8">Closed <span title="2017-04-13 12:07:10Z" class="relativetime">3 years ago</span>.</div>
        </div>
    </aside>
 var email = document.getElementById("mail");
                      var adi = document.getElementById("ad");
                      var tel = document.getElementById("telno");
                      var mesaji = document.getElementById("mesaj");
                      if (email.value !== "" && adi.value !== "" && tel.value !== "" && mesaji.value !== "") {
                      $.ajax({
                          url: "WebService1.asmx/Postala",
                          type: "POST",
                          data: "{ adi:'" + adi.value + "',mail:'" + email.value + "',no:'" + tel.value + "',icerik:'" + mesaji.value + "'}",
                          contentTpye: "application/json; charset=utf-8;",
                          dataType:"json",

                          success: function (msg) {
                              if (msg.d == true) {
                                  swal("Başarılı", "İletiniz Başarıyla Gönderildi", "success");
                                  setInterval(function () { location.reload() }, 1500);
                              }
                              else {
                                  swal("Üzgünüm", "İletiniz Gönderilemedi", "danger");
                              }
                          }

                      });

And this is my webservice code

        [WebMethod]
        public bool Postala(string adi,string mail,string no,string icerik)
        {
            List<string> paramsss = new List<string>() { "@ad", "@mail", "@no", "@icerik" };
            List<object> deger = new List<object>() {adi,mail,no,icerik };
            return islem.sqlcalistir("Insert into Mesajlar(mesajatanad,mesajatanmail,mesajatanno,mesajicerik) VALUES(@ad,@mail,@no,@icerik)",paramsss,deger);
        }

My Error is ; System.InvalidOperationException: Missing Parameter: adi. I controlled everything but I couldnt find anything

</div>
  • 写回答

1条回答 默认 最新

  • 北城已荒凉 2017-04-13 10:39
    关注

    You've told the server you're posting JSON, but you're not posting (valid) JSON. Valid JSON puts double quotes around property names, only uses " (not ') around strings, and ensures that the content of strings is properly escaped. Your code producing the JSON by hand doesn't do those things.

    Don't hand-serialize JSON; let JSON.stringify do it for you:

    data: JSON.stringify({
        adi: adi.value,
        mail: email.value,
        no: tel.value,
        icerik: mesaji.value
    })
    

    That creates an object with those properties, then lets JSON.stringify properly serialize it to JSON for you.

    评论

报告相同问题?

悬赏问题

  • ¥15 素材场景中光线烘焙后灯光失效
  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器