php教程 ajax 实例与ajax 教程
1创建xmlhttprequest对象的网页特效程序。
2 发出异步请求的javascript程序。
3 处理服务器响应的javascript程序。
*/
//1创建xmlhttprequest对象的javascript程序。
function getxmlhttprequest()
{
var xmlhttp=null;
try
{
xmlhttp = new xmlhttprequest(); //对于firefox等浏览器
}
catch(e)
{
try
{
xmlhttp = new activexobject(msxml2.xmlhttp); //对于ie浏览器
}
catch (e)
{
try
{
xmlhttp = new activexobject(microsoft.xmlhttp);
}
catch(e)
{
xmlhttp = false;
}
}
}
return xmlhttp;
}
//2 发出异步请求的javascript程序。
function sendrequest()
{
//获取页面表单的文本框name的值
var user_name = document.getelementbyid(name).value;
if((user_name == null) || (user_name == ))
return;
xmlhttp = getxmlhttprequest();
if(xmlhttp == null)
{
alert(浏览器不支持xmlhttprequest!);
return;
}
var url = getusername.php; //构建请求的url地址
url = url + ?name= + user_name;
xmlhttp.open(get, url, true); //使用get方法打开一个到url的连接,为发出请求做准备
//设置一个函数,当服务器处理完请求后调用,该函数名为updatepage
xmlhttp.onreadystatechange = updatepage;
xmlhttp.send(null); //发送请求
}
// 3 处理服务器响应的javascript程序。
function updatepage()
{
if(xmlhttp.readystate == 4)
{
var response = xmlhttp.responsetext;
document.getelementbyid(userinfo).value = response;
}
}
http://www.bkjia.com/phpjc/632054.htmlwww.bkjia.comtruehttp://www.bkjia.com/phpjc/632054.htmltecharticlephp ajax 实例与ajax 教程 1创建xmlhttprequest对象的javascript程序。 2 发出异步请求的javascript程序。 3 处理服务器响应的javascript程序。 php教程 aj...
