Home > Web Front-end > JS Tutorial > Ajax synchronous and asynchronous transmission sample code_javascript skills

Ajax synchronous and asynchronous transmission sample code_javascript skills

WBOY
Release: 2016-05-16 17:13:24
Original
1598 people have browsed it
Copy code The code is as follows:

//Synchronous transmission mode

function RequestByGet(nProducttemp ,nCountrytemp)
{
var xmlhttp

if (window.XMLHttpRequest)
{ //isIE = false;
xmlhttp = new XMLHttpRequest();

else if (window.ActiveXObject) 
 {                                                                     }

/ /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;
} 🎜>/ /Asynchronous transfer mode
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;
}
}

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template