$(function () {
            $("#Button1").click(function () {
                $.ajax({
                    type: "post",
                    url: "JQUERY.aspx/Inserts",
                    contentType: "application/json; charset=utf-8",
                    dataType: "json",
                 data: "id=" + $("#TextBox1").val() + "&name=" + $("#TextBox2").val() ,
             
                    success: function (data) {
                        alert("ok");
                    },
                    error: function (xhr) {
                        alert("错误" + xhr.responseText);
                    }
                });
                $("#Button1").attr("disabled", true);
               // return false;
            });
        }); 
    </script>
    <asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>   
        <asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>
     <asp:button ID="Button1" runat="server" text="Button" onclick="Button1_Click" />增加功能
我在后台写了个webservice,通过$.ajax()调用webservce,可是data里传的值总是报错,说什么“无效的json类型 id”
求解!!!!!!!!!!!!jquerywebservicejavascriptjsonfunction

解决方案 »

  1.   

    本帖最后由 showbo 于 2013-09-13 09:31:29 编辑
      

  2.   

    data部分改为json格式,或者你看看processData选项
    参考:
    http://www.ostools.net/apidocs/apidoc?api=jquery
      

  3.   

    key:value 的形式你参数传错了。
      

  4.   

    json.stringify($("#<%=TextBox1.ClientID%>").val())试一试
      

  5.   

    .net的webservice Inserts方法怎么写的,jquery传递的json要和方法参数名称要一致
      

  6.   


      [WebMethod]
        public static string Inserts(string id,string name)
        {
            bool result = Manager.InsertDep(id,name);
            if (result)
            {
                return "success";
            }
            else
            {
                return "fail";
            }
        }
    这就是后台方法
      

  7.   

    data: '{"id":"' + $("#TextBox1").val() + '","name":"' + $("#TextBox2").val()+'"}' ,name少了左边的",