// Here we use Bcandy as the method name to thank someone who is very important to me and she has been supporting me.
Function Bcandy (Tid, url, parm, js ){
If (url = ""){
Return;
}
// This is a prompt box for loading information, or not!
Document. getElementById ("load"). style. visibility = "visible ";
// Load the JS file of the corresponding page
If (js! = Null ){
// Load the JS File
LoadJS (js );
}
// Obtain an XMLHttpRequest instance
Var req = newXMLHttpRequest ();
// Set 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 ");
// Sending Parameters
Req. send (parm );
}
Function getReadyStateHandler (req, Tid ){
// Returns an anonymous function that listens to the XMLHttpRequest instance.
Return function (){
// If the request status is "complete"
If (req. readyState = 4 ){
// The server response is successfully received.
If (req. status = 200 ){
// The following sentence is important. The content of the returned information is displayed and can be modified. Other Processing
Document. getElementById (Tid). innerHTML = req. responseText;
Document. getElementById (Tid). style. visibility = "visible ";
// This statement is used to hide or hide the loading prompt box.
Document. getElementById ("load"). style. visibility = "hidden ";
} Else {
// An HTTP Error occurs.
Document. getElementById ("load"). style. visibility = "hidden ";
Alert ("HTTP error:" + req. status );
}
}
}
}
// Dynamically load 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 );
}