Ajax连接数据库

var xhr = '';

function Ajax()
{
if(window.XMLHttpRequest)
{
var xhr = new XMLHttpRequest;//现代浏览器
}else{
var xhr = new ActiveXObject('Microsoft.XMLHTTP');//IE
}
}

Ajax();//1.获取Ajax对象

xhr.onreadystatechange = function()
{
if(xhr.readyState == 4 && xhr.status == 200)
{
var data = xhr.responseText;//2.判断状态,接收数据(字符串形式),后续操作
}
}

//xhr.open('请求方式', '请求地址', TRUE);//3.异步传输连接
//xhr.send([data]);//4.发送请求

xhr.open('GET', 'demo.php?name=weichen&sex=0', TRUE);

xhr.send();

posted @ 2014-05-26 13:30  尐聪灬Con_ng  阅读(314)  评论(0编辑  收藏  举报