使用jquery實現(xiàn)簡單的ajax
更新時間:2013年07月08日 09:20:32 作者:
本篇文章是對用jquery實現(xiàn)簡單的ajax的實現(xiàn)方法進(jìn)行了詳細(xì)的分析介紹,需要的朋友參考下
-->html頁
<!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>
<title>用戶名校驗實例</title>
<script src="../js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../js/verify.js" type="text/javascript"></script>
</head>
<body onload="verify()">
用戶名校驗的jax實例
<!--ajax方式下不需要使用表單進(jìn)行數(shù)據(jù)提交,因此不用寫表單-->
<input type="text" value="" id="userName" />
<input type="button" value="提交" onclick=""/>
<!--預(yù)留空間,顯示結(jié)果-->
<div id="result"></div>
<!--div is block,but span is inline--->
</body>
</html>
—>js頁
function verify() {
$("#userName").keyup(function () {
var user = $(this).val();
var userobj = $(this);
$.post("../index.aspx", { userobj: user }, callback);
});
}
function callback(data) {
$("#result").text(data);
}
—>aspx頁
<%
Response.Clear();
string str_name = Request["userobj"];
if (str_name == "xtyang")
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
Response.End();
%>
復(fù)制代碼 代碼如下:
<!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>
<title>用戶名校驗實例</title>
<script src="../js/jquery-1.7.2.js" type="text/javascript"></script>
<script src="../js/verify.js" type="text/javascript"></script>
</head>
<body onload="verify()">
用戶名校驗的jax實例
<!--ajax方式下不需要使用表單進(jìn)行數(shù)據(jù)提交,因此不用寫表單-->
<input type="text" value="" id="userName" />
<input type="button" value="提交" onclick=""/>
<!--預(yù)留空間,顯示結(jié)果-->
<div id="result"></div>
<!--div is block,but span is inline--->
</body>
</html>
—>js頁
復(fù)制代碼 代碼如下:
function verify() {
$("#userName").keyup(function () {
var user = $(this).val();
var userobj = $(this);
$.post("../index.aspx", { userobj: user }, callback);
});
}
function callback(data) {
$("#result").text(data);
}
—>aspx頁
復(fù)制代碼 代碼如下:
<%
Response.Clear();
string str_name = Request["userobj"];
if (str_name == "xtyang")
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
Response.End();
%>
相關(guān)文章
jquery處理頁面彈出層查詢數(shù)據(jù)等待操作實例
這篇文章主要介紹了jquery處理頁面彈出層查詢數(shù)據(jù)等待操作,實例分析了jquery實現(xiàn)等待效果的技巧,具有一定參考借鑒價值,需要的朋友可以參考下2015-03-03
firefox下jquery ajax返回object XMLDocument處理方法
使用jquery ajax處理struts2 返回json類型的時候,ajax執(zhí)行成功返回結(jié)果為object XMLDocument,解決方法如下2014-01-01

