Ajax学习笔记
来源:互联网 发布:ff14人男捏脸数据 编辑:程序博客网 时间:2024/05/01 06:14
Ajax技术应该是时下Web开发最火的技术了吧,,减轻了服务器的处理量,实现无刷新重载来增强了用户体验。最大限度的减少对服务器的冗余请求...........................
今天又看到了baidu利用Ajax技术处理跨界的新方法,确实令我眼前一亮,下面是一段baidu的脚本文件:
<SCRIPT LANGUAGE="JavaScript">
document.domain="baidu.com";
<!--
function G(id){if(typeof(id)=="string"){return document.getElementById(id);}return id;}
function showInfo(obj){
if(obj.checked == true){
G("memInfo").style.display="block";
}else{
G("memInfo").style.display="none";
}
}
function request(id,url){
oScript = document.getElementById(id);
var head = document.getElementsByTagName("head").item(0);
if (oScript) {
head.removeChild(oScript);
}
oScript = document.createElement("script");
oScript.setAttribute("src", url);
oScript.setAttribute("id",id);
oScript.setAttribute("type","text/javascript");
oScript.setAttribute("language","javascript");
head.appendChild(oScript);
return oScript;
}
var loginTimer=null;
var loginState=-1;
var tryTime=0;
function PSP_ik(isOk){
if(isOk==0){
G("errorInfo").style.display="none";
loginState=1;
if(parent.loginSuccess){
parent.Pop.hide();
parent.loginSuccess();
}
}
else
{
loginFalse();
}
}
function loginFalse(){
loginState=0;
var err=G("errorInfo");
err.innerHTML="用户名或密码错误,请重新登录";
err.style.display="block";
G("username").focus();
tryTime++;
if(tryTime>1){
onLoginFailed();
}
}
function onLoginFailed(){
if(parent.onLoginFailed){
parent.Pop.hide();
parent.loginFailed();
}else{
document.login.u.value=escape("http://zhidao.baidu.com/q"+parent.location.search);
doucment.login.submit();
}
}
function loginTimeout(){
if(loginState==-1){
var err=G("errorInfo");
err.innerHTML="操作超时,请重新登录";
err.style.display="block";
G("username").focus();
}
}
function userLogin(){
var username=G('username').value;
var password=G('password').value;
var memPassport=G('memPassport').checked?"on":"off";
if(username.length <=0||password.length <=0){G("username").focus();return false;}
var url = 'https://passport.baidu.com/?logt&tpl=ik&t=0&keyname=ik&mem_pass='+memPassport+'&username='+username + '&loginpass=' +escape(password)+ '&s=' + (new Date()).getTime();
loginState=-1;
var login=request("loginScript",url);
loginTimer = setTimeout(loginTimeout, 5000);
}
window.onload=function(){
document.loginForm.username.focus();
document.getElementById("username").focus();
}
//-->
</SCRIPT>
我一般都会用xmlhttp发送get请求实现,但百度用的是request方法处理异步请求使用动态往head中添加script,当页面加载后,可以达到相同的效果,同时完美地解决了跨界的问题,确实很精妙。
- ajax学习笔记---什么是Ajax
- [ajax 学习笔记] ajax初试
- Ajax学习笔记-Ajax数据格式
- AJAX学习笔记--慕课网Ajax
- Ajax学习笔记(一)
- Ajax学习笔记(二)
- Ajax学习笔记(三)
- Ajax学习笔记(四)
- Ajax学习笔记(五)
- Ajax学习笔记(六)
- Ajax学习笔记
- Ajax 学习笔记(1)
- Ajax 学习笔记(2)
- Ajax 学习笔记(3)
- Ajax Gossip学习笔记
- AJAX学习笔记--从零开始
- Ajax 学习笔记
- ajax学习笔记
- JS在页面上显示当前日期和时间
- 关于Excel中单元格引用的本质
- 1_页面中怎样加载一个地图
- 在MSDN上找到的适合初学者的教程。从孩子的水平教起,直到骨灰级专家
- 内外忽悠,软件业能怎样发展?
- Ajax学习笔记
- 窗口和控件样式参考
- 在PL/SQL中借助JAVA调用可执行程序的例子
- 一个基于v4l2框架的输出驱动分析
- SWF文件结构研究
- 教程
- 制作抖动窗体
- 全局对象何时析构
- 乱