About_AJAX
Asynchronous JavaScript And XML
(1)AJAX大多用于验证和分页;
(2)首先要激活(对象):
window.ActiveXObject(针对IE);
window.XMLHttpRequest(针对其他浏览器)
eg(验证):
1、首先需要一个登录界面
<html>
<head>
<title>firstAjax</title>
<meta http-equiv="Content-Type" content="text/html;charset=UTF-8"/>
</head>
<body>
<form action="">
用户名:<input type="text" name="users" id="" onblur="Changes(this.value)"/>
<span style="color: #ff0000;font-size: 16px;font-weight: bold" id="promit"></span><br/>
密 码:<input type="text"/><br/>
<input type="submit" name="submit" value="提交"/>
</form>
</body>
<script type="text/javascript" src="ajax.js"></script>
</html>
2、从数据库中验证用户是否注册
<?php
if(isset($_GET['users'])){
$users = $_GET['users']; $conn = mysql_connect("localhost","","") or die("数据库连接失败!");
mysql_select_db("test");
mysql_query("set names 'utf8'"); $sql = "select count(*) from `user_pwd` where users = '$users'";
$result = mysql_query($sql);
$row = mysql_fetch_row($result); if($row[0]){
echo "抱歉、该用户已经被注册!";
}else{
echo "您可以注册";
}
}
?>
3、用AJAX验证
var XmlHttp;//声明对象 //第一个function是判断浏览器,并激活对象
function ActiveHttp(){
if(window.ActiveXObject){// 万恶的IE使用 ActiveX 对象
XmlHttp = new ActiveXObject("MICROSOFT.XMLHTTP");
}else if(window.XMLHttpRequest){//其他浏览器使用 ActiveX 对象
XmlHttp = new XMLHttpRequest();
}
} //第二个function是php中调用的函数
function Changes(url){
ActiveHttp();
XmlHttp.open("GET","yanZLog.php?users="+url,true);
//XmlHttp.open里面有三个参数:1、选择get还是post(我们最好使用get,如果用post的话要加上: setRequestHeader("Content-Type","application/x-www-form-urlencoded");)
//2、php验证地址
//3、true:使用AJAX;false:不使用
XmlHttp.onreadystatechange = doThing;
XmlHttp.send(null);//必不可少的!!
} //第三个function是具体要干的事
function doThing(){
if(XmlHttp.readyState == 4){//对象状态(integer):0=未初始化,1=读取中,2=已读取,3=交互中,4=完成
if(XmlHttp.status == 200){//服务器返回的状态码,如404=“文件未找到”、200=“成功”
var sp = document.getElementById("promit");
sp.innerHTML = XmlHttp.responseText;
}
}
}
About_AJAX的更多相关文章
- django之ORM的查询优化、Ajax 06
目录 ORM查询优化 only与defer select_related与prefetch_related查询优化 choices参数 MTV与MVC模型 Ajax简介 AJAX常见应用情景 AJAX ...
随机推荐
- 注解:【有连接表的】Hibernate单向N->1关联
Person与Address关联:单向N->1,[有连接表的] Person.java package org.crazyit.app.domain; import javax.persiste ...
- Linux学习笔记(4)Linux常用命令之权限管理命令
(1)chmod chmod命令用于改变文件或目录权限,英文原意为change the permissions mode of a file,所在路径为/bin/chmod,其语法格式为: chmod ...
- Sql数据库帮组类
这段时间闲下来写了一些东西,重新写了一个简单的数据库帮组类 public class MyDBHelper { public static readonly string connString = C ...
- Codeforces Round #355 (Div. 2)-A
A. Vanya and Fence 题目连接:http://codeforces.com/contest/677/problem/A Vanya and his friends are walkin ...
- Codeforces Round #354 (Div. 2)-A
A. Nicholas and Permutation 题目链接:http://codeforces.com/contest/676/problem/A Nicholas has an array a ...
- coffeeScript学习02
闭包 closure = do -> _private = "foo" -> _private console.log(closure()) #=> " ...
- Swift3.0语言教程删除字符与处理字符编码
Swift3.0语言教程删除字符与处理字符编码 Swift3.0语言教程删除字符 Swift3.0语言教程删除字符与处理字符编码,在字符串中,如果开发者有不需要使用的字符,就可以将这些字符删除.在NS ...
- Web Service \restful web services\WCF Service\ServiceStack
http://www.cnblogs.com/jfzhu/p/4025448.html http://www.cnblogs.com/jfzhu/p/4022139.html#3043243
- js动画实现侧边栏分享
<!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...
- 一个简单的dos脚本, svn 获取代码 - Tomcat 备份 - Maven 编译 - 停止/启动Tomcat - Tomcat站点 发布
获取最新代码 svn update --username %SVN_USER% --password %SVN_PASSWORD% >> "../%LOG_FILE%" ...