手机
当前位置:查字典教程网 >编程开发 >Javascript教程 >Ajax同步与异步传输的示例代码
Ajax同步与异步传输的示例代码
摘要:复制代码代码如下://同步传输模式functionRequestByGet(nProducttemp,nCountrytemp){varxm...

复制代码 代码如下:

//同步传输模式

function RequestByGet(nProducttemp,nCountrytemp)

{

var xmlhttp

if (window.XMLHttpRequest)

{

//isIE = false;

xmlhttp = new XMLHttpRequest();

}

else if (window.ActiveXObject)

{

//isIE = true;

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

//Web page location.

var URL="http://www.jb51.net/;

xmlhttp.open("GET",URL, false);

//xmlhttp.SetRequestHeader("Content-Type","text/html; charset=Shift_JIS")

xmlhttp.send(null);

var result = xmlhttp.status;

//OK

if(result==200)

{

document.getElementById("div_RightBarBody").innerHTML=xmlhttp.responseText;

}

xmlhttp = null;

}

//异步传输模式

var xmlhttp

function RequestByGet(nProducttemp,nCountrytemp)

{

if (window.XMLHttpRequest)

{

//isIE = false;

xmlhttp = new XMLHttpRequest();

}

else if (window.ActiveXObject)

{

//isIE = true;

xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");

}

//Web page location.

var URL="http://www.jb51.net/";

xmlhttp.open("GET",URL, true);

xmlhttp.onreadystatechange = handleResponse;

//xmlhttp.SetRequestHeader("Content-Type","text/html; charset=UTF-8")

xmlhttp.send(null);

}

function handleResponse()

{

if(xmlhttp.readyState == 4 && xmlhttp.status==200)

{

document.getElementById("div_RightBarBody").innerHTML=xmlhttp.responseText;

xmlhttp = null;

}

}

【Ajax同步与异步传输的示例代码】相关文章:

js实现异步循环实现代码

光标定位等TextRange的操作的范例代码

解析javascript中鼠标滚轮事件

鼠标图片振动代码

JavaScript中Number.MIN_VALUE属性的使用示例

简单的防盗链功能代码(iframe)

AngularJS中的一些常用指令介绍

javascript中FOREACH数组方法使用示例

多附件上传组件演示

一段实时更新的时间代码

精品推荐
分类导航