get和post的区别
说明:无论是用ajax还是form表单来实现交互,首先我们要明确get和post的使用场合
get是限制长度的,post不会
get请求数据大小不超过2000字符左右,post无限制
get请求的查询字符串显示在地址栏,post不会,即是post更安全
本文实现功能
通过ajax的get或post方法,发送一个查询字符串uname=lisi&upwd=123456请求,并响应回来结果,信息正确与否;
common.js文件
common.js文件,简化一些dom操作和复杂固定步骤
function $(id) {
return document.getElementById(id);
} //简化document.getElementById()这个api
function createXhr(){//简化创建异步对象
var xhr=null;
if(window.XMLHttpRequest==null){
xhr=new ActiveXObject(“Microsoft.XMLHttp”);
}else{
xhr=new XMLHttpRequest();
}
return xhr;
}
ajax.php
用于接收网页传过来的请求数据,并返回结