好吧,我使用带有 PageMethod 的 jquery ajax 来提交表单,但是我的表单有一个 asp.net 验证器,ajax 并且从 pageMethod 返回值很好,但是验证器不再工作,这是我的代码
<script type="text/javascript">
$(document).ready(function () {
// Add the page method call as an onclick handler for the div.
$("#Label1").click(function () {
$.ajax({
type: "POST",
url: "Default.aspx/GetDate",
data: "{}",
contentType: "application/json; charset=utf-8",
dataType: "json",
success: function (msg) {
// Replace the div's content with the page method's return.
$("#Label2").text(msg.d.b);
if (!msg.d.b) {
$("#Label1").hide();
}
}
});
});
});
</script>
后面的代码是这样的
[WebMethod]
public static object GetDate()
{
SqlConnection con = new SqlConnection();
con.ConnectionString = "Data Source=ad;Initial Catalog=Test;Integrated Security=True";
string query="insert into test(name,family) values('mehdi','jabbari')";
con.Open();
SqlCommand cmd = new SqlCommand(query,con);
cmd.ExecuteNonQuery();
con.Close();
return new{
b=false
};
}
谢谢你