Ajax-based infinite-level menu _ajax related

Source: Internet
Author: User
Tags visibility

Non-flash commit for form (a bit stupid)
Supports the MVC framework, which supports traditional Web page architectures
Multithreading concurrent requests (for language support threads)
Dynamically loading files, loading only useful! Handled the AJAX framework bloated JS file problem.
Full div + CSS layout with no table

A. Access to XMLHttpRequest objects, found everywhere on the internet, not much said:

function Newxmlhttprequest () {
var xmlreq = false;
if (window. XMLHttpRequest) {
XMLreq = new XMLHttpRequest ();
else if (window. ActiveXObject) {
try {
XMLreq = new ActiveXObject ("Msxml2.xmlhttp");
} catch (E1) {
try {
XMLreq = new ActiveXObject ("Microsoft.XMLHTTP");
} catch (E2) {
}
}
}
return xmlreq;
}
This provides a common way to support multiple browsers.

B. Making an asynchronous request

//here with Bcandy as the method name is to thank someone who is very important to me, she has been supporting me
function Bcandy (tid,url,parm,js) {
if (url = = "") {
return;
}
//This is a load information prompt box, or you can not!
document.getElementById ("Load"). style.visibility = "visible";
//loading the corresponding page of the JS file
if (JS!= null) {
//load JS file
Loadjs (JS);
}
//Get a XMLHttpRequest instance
var req = Newxmlhttprequest ();
Sets the handle function used to receive callback notifications from the Request object
var handlerfunction = Getreadystatehandler (Req,tid);
Req.onreadystatechange = handlerfunction; The
//third parameter indicates that the request is asynchronous
Req.open ("POST", url, true);
Indicates that the request Body contains form data
Req.setrequestheader ("Content-type",
"application/x-www-form-urlencoded");
Send parameter
req.send (parm);
}

function Getreadystatehandler (req,tid) {
//Returns an anonymous function that listens on the XMLHttpRequest instance
return function () {
//If the status of the request is ' completed '
if (req.readystate = 4) {
///////successfully received the server response
if (Req.status =) {
//The following sentence is the focus, which The content section of the returned information is displayed and can be modified. For other processing
document.getElementById (Tid). InnerHTML = Req.responsetext;
document.getElementById (Tid). style.visibility = "visible";
//This is the hidden or not to implement the load information balloon.
document.getElementById ("Load"). Style.visibility = "hidden";
} else {
//has HTTP problem occurs
document.getElementById ("Load"). Style.visibility = "hidden";
Alert ("HTTP error:" +req.status);
}
}
}
}


Dynamically Loading JS files
function Loadjs (file) {
var head = document.getElementsByTagName (' head '). Item (0);
var script = document.createelement (' script ');
script.src = file;
Script.type = "Text/javascript";
Head.appendchild (script);
}
This is the basic framework because of the use of request.responsetext, so you can request a page directly jsp,servlet but when you use the Struts framework request for special processing, because the form does not support asynchronous requests. It is recommended that you do not add Overall, it's kind of like building blocks. This facilitates the modification and extension of the file, and does not affect each other, and realizes code and label separation. When you make a traditional page revision, you don't have to rewrite all the code. Only a small number of changes can be a perfect AJAX to achieve the flash-free refreshing pleasure.

The above code has been tested under Ie,firefox!

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.