我的脚本
<script type ="text/javascript">
$(document).ready(function () {
$('#<%=Button1.ClientID %>').click(function () {
var ABC = 'TEST';
$.ajax({
type: "POST",
url: "Default.aspx/ServerSideMethod" ,
data: "{ EmailAddress : ABC }",
contentType: "application/json; charset=utf-8",
dataType: "json",
async: true,
cache: false,
success: function (msg) {
alert(msg);
$('#myDiv').text(msg.d);
}
})
return false;
});
});
</script>
代码隐藏方法
[WebMethod]
public static string ServerSideMethod(string EmailAddress)
{
return EmailAddress ;
}
<asp:Button ID="Button1" runat="server" Text="Click" />
<br /><br />
<div id="myDiv"></div>
在按钮单击它给我InvalidJSONprimitive:ABC这个错误可以告诉任何人我做错了什么。