日期:2014-05-16 浏览次数:20622 次
<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="JqueryAJAX.aspx.cs" Inherits="JqueryAJAX.JqueryAJAX" %> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head id="Head1" runat="server"> <title></title> <script language="javascript" type="text/javascript" src="jquery-1.3.1.js"></script> <script language="javascript" type="text/javascript"> $(function () { $("#btnOK").click(function () { Add(); }); }) function Add() { var NO = $("#txtNO").val(); var name = $("#txtName").val(); var clas = $("#txtClass").val(); var sex2 = $("input[type=radio][checked]").val(); var sex = $('input:radio:checked').val(); var param = "{'NO':'" + NO + "','name':'" + name + "','clas':'" + clas + "','sex':" + sex + "}"; alert(param); $.ajax({ type: "POST", url: "JqueryAJAX.aspx/AddInfo", data: param, contentType: "application/json; charset=utf-8", dataType: "json", timeout: 60000, error: function (XMLHttpRequest, textStatus, errorThrown) { alert("error:" + errorThrown); }, beforsend: function () { $("#btnOK").attr("value", "正在提交..."); }, success: function (msg) { if (msg.d == null) { return; } var result = msg.d; if (result > 0) { $("#btnOK").attr("value", "提交"); alert("OK"); } else { $("#btnOK").attr("value", "提交"); alert("Error"); } }, complete: function (XMLHttpRequest, textStatus) { $("#btnOK").attr("value", "提交完成"); } }); } </script> </head> <body> <form id="form1" runat="server"> <div> 学号:<input id="txtNO" type="text" /><br /> 姓名:<input id="txtName" type="text" /><br /> 班级:<input id="txtClass" type="text" /><br /> 性别:<input id="Radio1" name="sex" type="radio" value="1" checked="checked" />男<input id="Radio2" type="radio" name="sex" value="0" />女 <input id="btnOK" type="button" value="提交" /></div> </form> </body> </html>
using System; using System.Collections.Generic; using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; using System.Data.SqlClient; using System.Text; using System.Web.S