您的位置:首页 > Web前端 > JQuery

jQuery+AJAX+ASP.NET简单实例

2009-05-22 21:11 573 查看
做了这么久的程序,用jQuery框架还是第一次哦,例子虽然简单,不过,麻雀虽小,什么都全嘛!有个思路就好扩展了!

开始吧!

(一)index.aspx(html代码)

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default2.aspx.cs" Inherits="Default2" %>

<!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 runat="server">

<title>无标题页</title>

<script language ="javascript" type="text/javascript" src="js/jquery-1[1].3.2.js"></script>

<script language ="javascript" type="text/javascript" >

$(document).ready(function(){

$("#Button1").click(function(){

myLogin();

});

});

function myLogin()

{

if(IsValidate()==true)

{

$.post("text.aspx",{Action:"post",userID:$("#TextBox1").val(),userPwd:$("#TextBox2").val()}

,function(aa,textStatus){

//alert(aa.name);

$("#mydiv").html(aa.qq);

},"json" );

}

}

function IsValidate()

{

if($("#TextBox1").val()=="")

{

alert("用户名不能为空!");

$("#TextBox1").focus();

return false;

}

if($("#TextBox2").val()=="")

{

alert("密码不能为空!");

$("#TextBox2").focus();

return false;

}

return true;

}

</script>

</head>

<body>

<form id="form1" runat="server">

用户名:<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>

<br />

密码:<asp:TextBox ID="TextBox2" runat="server"></asp:TextBox>

<br />

<input id="Button1" type="button" value="提交" /></form>

<div id="mydiv"></div>

</body>

</html>

(二)处理页(text.aspx)

protected void Page_Load(object sender, EventArgs e)

{

string reVal = "";

string userID = Request["userID"];

string userPwd=Request["userPwd"];

if (userID == "chenqiao" && userPwd == "chenqiao")

{

reVal = "result:'success'";

}

else

{

reVal = "result:'fail',name:'chenqiao',qq:'sdfkas;dfkas;df<p>asdfasd</p>'";

}

Response.ContentType = "application/json";

Response.Write("{"+reVal+"}");

Response.End();

}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: