$(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
参考:
http://www.ostools.net/apidocs/apidoc?api=jquery
[WebMethod]
public static string Inserts(string id,string name)
{
bool result = Manager.InsertDep(id,name);
if (result)
{
return "success";
}
else
{
return "fail";
}
}
这就是后台方法