用jquery使用ajax例子
来源:互联网 发布:java中变量的定义方法 编辑:程序博客网 时间:2024/05/01 10:33
数据库test 表ta
表内容:
+----+------+
| id | name |
+----+------+
| 1 | aa |
| 2 | bb |
+----+------+
***************************************************************************
展示文件test.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>jquery_ajax</title>
<script language="javascript" src="jquery.js"></script>
<style type="text/css">
#msg{
background:yellow;
width:500px;
height:300px;
display:block;
}
</style>
<script language="javascript">
$(document).ready(function(){
$("#user").keyup(function(){
var username = $(this).val();
var url = "ajax.php";
if(username != ""){
$.get(url,
{name:username},
function(data){
if(data == 0){
$("#msg").html("可以注册!");
}
else{
$("#msg").html("用户名已经使用!");
}
}
);
}
else{
$("#msg").html("用户名为空!");
}
});
})
</script>
</head>
<body>
<input type="text" id="user" name="user" />
<span id="msg"></span>
</body>
</html>
+----------------------------------------------------+
ajax调用文件:
ajax.php
<?php
/**
*查询用户名
*
*/
mysql_connect("localhost","usr","pwd");
mysql_select_db("test");
$str = "select count(name) from ta where name='{$_GET['name']}';";
$query = mysql_query($str)or die("aaaaaaa");
while($row = mysql_fetch_row($query)){
echo $row[0];
}
?>
*******************************
ajax的另一种写法
<script language="javascript">
$(document).ready(function(){
$("#user").keyup(function(){
if(event.keyCode == 13){
return false;
};
var username = $("#user").val();
var url = "ajax.php";
$.ajax({
type:"GET",
url:"ajax.php",
data:"name="+username,
success:function(msg){
if(msg == 0){
$("#msg").html("用户名可以使用!");
}
else{
$("#msg").html("<font color='red'>用户名已经被使用!</font>");
}
}
});
});
})
</script>
表内容:
+----+------+
| id | name |
+----+------+
| 1 | aa |
| 2 | bb |
+----+------+
***************************************************************************
展示文件test.php
<html>
<head>
<meta http-equiv="content-type" content="text/html;charset=utf-8">
<title>jquery_ajax</title>
<script language="javascript" src="jquery.js"></script>
<style type="text/css">
#msg{
background:yellow;
width:500px;
height:300px;
display:block;
}
</style>
<script language="javascript">
$(document).ready(function(){
$("#user").keyup(function(){
var username = $(this).val();
var url = "ajax.php";
if(username != ""){
$.get(url,
{name:username},
function(data){
if(data == 0){
$("#msg").html("可以注册!");
}
else{
$("#msg").html("用户名已经使用!");
}
}
);
}
else{
$("#msg").html("用户名为空!");
}
});
})
</script>
</head>
<body>
<input type="text" id="user" name="user" />
<span id="msg"></span>
</body>
</html>
+----------------------------------------------------+
ajax调用文件:
ajax.php
<?php
/**
*查询用户名
*
*/
mysql_connect("localhost","usr","pwd");
mysql_select_db("test");
$str = "select count(name) from ta where name='{$_GET['name']}';";
$query = mysql_query($str)or die("aaaaaaa");
while($row = mysql_fetch_row($query)){
echo $row[0];
}
?>
*******************************
ajax的另一种写法
<script language="javascript">
$(document).ready(function(){
$("#user").keyup(function(){
if(event.keyCode == 13){
return false;
};
var username = $("#user").val();
var url = "ajax.php";
$.ajax({
type:"GET",
url:"ajax.php",
data:"name="+username,
success:function(msg){
if(msg == 0){
$("#msg").html("用户名可以使用!");
}
else{
$("#msg").html("<font color='red'>用户名已经被使用!</font>");
}
}
});
});
})
</script>
- 用jquery使用ajax例子
- JQuery Autocomplete使用Ajax例子
- Ajax + JQuery + JSON + Struts使用例子
- jquery中ajax的使用例子($.ajax())
- jQuery ajax 例子
- jQuery ajax 例子
- jquery 结合ajax例子
- jquery - ajax - json 例子
- jQuery Ajax例子
- jquery ajax例子
- Jquery ajax例子
- jquery之ajax例子
- jquery+ajax小例子。
- jquery.ajax 的例子
- Jquery ajax例子
- jquery ajax的例子
- servlet+jquery+ajax+json 例子
- jquery+ajax简单的例子
- JQuery ajax请求的2种用法
- ASC码
- 数据库优化
- jquery运用b
- MT6253平台启动流程
- 用jquery使用ajax例子
- HTML学习(6)使用样式
- 笔记本电脑忘记开机密码怎么办?
- 学习日志—序
- 使用jquery点击换图片
- 使用jquery的ajax取xml
- MFC画坐标曲线图(转)
- jquery的ajax中的几种状态
- copy constructor