您的位置:首页 > 编程语言 > PHP开发

PHP后台

2013-12-28 22:26 162 查看
一、ajax提交表单

先引入ajax.js

function ajax(url, fnSucc, fnFaild)
{
//1.创建Ajax对象
var oAjax=null;

if(window.XMLHttpRequest)
{
oAjax=new XMLHttpRequest();
}
else
{
oAjax=new ActiveXObject("Microsoft.XMLHTTP");
}

//2.连接服务器
oAjax.open('GET', url, true);

//3.发送请求
oAjax.send();

//4.接收服务器的返回
oAjax.onreadystatechange=function ()
{
if(oAjax.readyState==4)    //完成
{
if(oAjax.status==200)    //成功
{
fnSucc(oAjax.responseText);
}
else
{
if(fnFaild)
fnFaild(oAjax.status);
}
}
};
}


然后

var url='loginAct.php?user='+oTxt.value;//alert(url);
ajax(url,function(str){console.log(str);
if(str==1){
oUser.value=oTxt.value+'Welcome to here';//alert('Welcome to here');
}else{
alert('your name is error');
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: