脚本宝典收集整理的这篇文章主要介绍了js实例教程-使用jquery实现简单的ajax,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。小宝典致力于为广大程序猿(媛)提供高品质的代码服务,请大家多多光顾小站,小宝典在此谢过。
-->htML页
. 代码如下:
<!DOCTYPE html PubLIC "-//W3C//DTD XHTML 1.0 TransITional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html XMlns="https://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方式下不需要使用表单进行数据提交,因此不用写表单-->
<input type="text" value="" id="userName" />
<input type="button" value="提交" onclick=""/>
<!--预留空间,显示结果-->
<p id="result"></p>
<!--p is block,but span is inline--->
</body>
</html>
. 代码如下:
function verify() {
$("#userName").keyup(function () {
VAR user = $(this).val();
var userobj = $(this);
$.post("../index.aspx", { userobj: user }, callback);
});
}
function callback(data) {
$("#result").text(data);
}
. 代码如下:
<%
Response.Clear();
string str_name = Request["userobj"];
if (str_name == "xtyang")
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
Response.End();
%>
-->html页
. 代码如下:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "https://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="https://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方式下不需要使用表单进行数据提交,因此不用写表单-->
<input type="text" value="" id="userName" />
<input type="button" value="提交" onclick=""/>
<!--预留空间,显示结果-->
<p id="result"></p>
<!--p is block,but span is inline--->
</body>
</html>
. 代码如下:
function verify() {
$("#userName").keyup(function () {
var user = $(this).val();
var userobj = $(this);
$.post("../index.aspx", { userobj: user }, callback);
});
}
function callback(data) {
$("#result").text(data);
}
. 代码如下:
<%
Response.Clear();
string str_name = Request["userobj"];
if (str_name == "xtyang")
{
Response.Write("ok");
}
else
{
Response.Write("no");
}
Response.End();
%>
觉得可用,就经常来吧!Javascript技巧 脚本宝典 欢迎评论哦! js技巧,巧夺天工,精雕玉琢。小宝典献丑了!
以上是脚本宝典为你收集整理的js实例教程-使用jquery实现简单的ajax全部内容,希望文章能够帮你解决js实例教程-使用jquery实现简单的ajax所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。