Tag navigation using ajax

Source: Internet
Author: User
Tags http 200

Main functions: Copy codeThe Code is as follows: <! --
Function getObject (objectId ){
If (document. getElementById & document. getElementById (objectId )){
// W3C DOM
Return document. getElementById (objectId );
}
Else if (document. all & document. all (objectId )){
// MSIE 4 DOM
Return document. all (objectId );
}
Else if (document. layers & document. layers [objectId]) {
// NN 4 DOM.. note: this won't find nested layers
Return document. layers [objectId];
}
Else {
Return false;
}
}

Var responsecont;
Var xmlHttp;
Var requestType;
Var newsstring;

Function CreateXMLHttpRequest (){
// Initialize Mozilla XMLHttpRequest object
If (window. XMLHttpRequest ){
XmlHttp = new XMLHttpRequest ();
}
// Initialize for IE/Windows ActiveX version
Else if (window. ActiveXObject ){
Try {
XmlHttp = new ActiveXObject ("Msxml2.XMLHTTP. 3.0 ");
}
Catch (e ){
Try {
XmlHttp = new ActiveXObject ("Microsoft. XMLHTTP ");
}
Catch (e) {newsstring = "<div class = 'loading'> loading rquest content fail, Please try it again latter... </div> ";}
}
}
}

Function getnews (tagid, x ){
Var url = tagid='_'{x}'.htm ';
Var loadstatustext = "<div class = 'loading'> loading request content, please wait... </div> ";
RequestType = tagid;
CreateXMLHttpRequest ();

GetObject (requestType + '_ cnt'). innerHTML = loadstatustext;
XmlHttp. onreadystatechange = processRequestChange;
XmlHttp. open ("GET", url, true );
XmlHttp. setRequestHeader ("If-Modified-Since", "0 ");
XmlHttp. send (null );
}

Function processRequestChange (){
// Only if xmlHttp shows "complete"
If (xmlHttp. readyState = 4 ){
// Only the http 200 to process
If (window. location. href. indexOf ("http") =-1 | xmlHttp. status = 200 ){
Newsstring = xmlHttp. responseText;
// Inject centent to tab-pane
Shownews (requestType, newsstring );
}
}
}

Function shownews (requestType, newsstring ){
// <! [CDATA [
Responsecont = getObject (requestType + '_ cnt ');
Responsecont. innerHTML = newsstring;
//]>
}

Function TabNews (tagid, x ){
For (var I = 1; I <= 7; I + = 2 ){
If (I = x ){
GetObject (tagid + I). className = "tabactive" + I;
If (I! = 1 ){
GetObject (tagid + (I-1). style. display = "none ";
If (I! = 7 ){
GetObject (tagid + (I + 1). style. display = "none ";
}
}
If (I = 1 ){
GetObject (tagid + "2"). style. display = "none ";
}
Try {
Getnews (tagid, I );
}
Catch (e ){
Alert (e );
}
}
Else
{
GetObject (tagid + I). className = "";
If (I! = 7 ){
GetObject (tagid + (I + 1). style. display = "block ";
}
}
}
}
// -->

Call method:Copy codeThe Code is as follows: <li style = "cursor: pointer" id = "tab3" onclick = "TabNews ('tab', 3)"> latest discount Information </li>

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.