jquery AJAX implementation without refreshing data loading code

Source: Internet
Author: User
Tags php tutorial


<meta http-equiv= "Content-type" content= "text/html; charset=gb2312 "/>
<title></title>

<script>
var xml_http_building_link = ' Please wait, connection is being established ... ';
var xml_http_sending = ' Please wait, sending data ... '
var xml_http_loading = ' Please wait, data is being accepted ... ';
var xml_http_load_failed = ' Communication failed, please refresh retry ';
var xml_http_data_in_processed = ' Communication success, data being processed ... '

Function Ajax (Statusid, Recvtype) {
 var aj = new Object ();
 if (document.getElementById (STATUSID)) {
  aj.statusid = document.getElementById (STATUSID);
 } else {
  var divelement = document.createelement ("DIV");
   Divelement.classname = "Xweb-ajaxmsg";
  divelement.style.position = "fixed";
  divelement.style.right = "0";
  divelement.style.top = "0";
  divelement.style.background = "Red";
  divelement.style.color = "#FFF";
  divelement.style.lineheight = "2EM";
  divelement.style.padding = "0 20px";
  divelement.id = Statusid;
  document.body.appendchild (divelement);
  aj.statusid = divelement;
 }
 
 aj.targeturl = ';
 aj.sendstring = ';
 aj.recvtype = recvtype? Recvtype: ' HTML ';//html XML
 aj.resulthandle = null;

Aj.createxmlhttprequest = function () {
var request = false;
if (window. XMLHttpRequest) {
Request = new XMLHttpRequest ();
if (Request.overridemimetype) {
Request.overridemimetype (' Text/xml ');
}
else if (window. ActiveXObject) {
var versions = [' Microsoft.XMLHTTP ', ' MSXML. XMLHTTP ', ' microsoft.xmlhttp ', ' msxml2.xmlhttp.7.0 ', ' msxml2.xmlhttp.6.0 ', ' msxml2.xmlhttp.5.0 ', ' msxml2.xmlhttp.4.0 ', ' MSXML2. xmlhttp.3.0 ', ' MSXML2. XMLHTTP '];
for (var i=0; i<versions.length; i++) {
try {
Request = new ActiveXObject (versions[i]);
if (request) {
return request;
}
catch (e) {
alert (e.message);
}
}
}
return request;
}

Aj. XMLHttpRequest = Aj.createxmlhttprequest ();

Aj.processhandle = function () {
Aj.statusId.style.display = ';
if (AJ. Xmlhttprequest.readystate = = 1) {
Aj.statusId.innerHTML = Xml_http_building_link;
else if (AJ. Xmlhttprequest.readystate = = 2) {
Aj.statusId.innerHTML = xml_http_sending;
else if (AJ. Xmlhttprequest.readystate = = 3) {
Aj.statusId.innerHTML = xml_http_loading;
else if (AJ. Xmlhttprequest.readystate = = 4) {
if (AJ. Xmlhttprequest.status = = 200) {
Aj.statusId.style.display = ' None ';
if (Aj.recvtype = = ' HTML ') {
Aj.resulthandle (AJ. Xmlhttprequest.responsetext);
else if (Aj.recvtype = = ' XML ') {
Aj.resulthandle (AJ. Xmlhttprequest.responsexml);
}
} else {
Aj.statusId.innerHTML = xml_http_load_failed;
}
}
}

 aj.get = function (TargetUrl, resulthandle) {
  aj.targeturl = TargetUrl;
  aj. Xmlhttprequest.onreadystatechange = Aj.processhandle;
  aj.resulthandle = Resulthandle;
  if (window. XMLHttpRequest) {
   aj. Xmlhttprequest.open (' Get ', aj.targeturl);
   aj. Xmlhttprequest.send (NULL);
  } else {
         aj. Xmlhttprequest.open ("Get", TargetUrl, True);
         AJ. Xmlhttprequest.send ();
  }
 }

Aj.post = function (TargetUrl, sendstring, Resulthandle) {
Aj.targeturl = TargetUrl;
aj.sendstring = sendstring;
Aj. Xmlhttprequest.onreadystatechange = Aj.processhandle;
Aj.resulthandle = Resulthandle;
Aj. Xmlhttprequest.open (' POST ', targeturl);
Aj. Xmlhttprequest.setrequestheader (' Content-type ', ' application/x-www-form-urlencoded ');
Aj. Xmlhttprequest.send (aj.sendstring);
}
return to AJ;
}
</script>

<body>
<div id= "Page" >
</div>

<script type= "Text/javascript Tutorial" language= "JavaScript" >
<!--
var pageval=getthe_hrefvar ("page");
var gethtmlfile= ".../www.111cn.net/product_list.php tutorial";
if (pageval>0)
{
Gethtmlfile=gethtmlfile + "page=" + pageval;
}
var Sortidval=getthe_hrefvar ("SortID");
if (sortidval)
{
if (Gethtmlfile.indexof ("?") >=0)
{
Gethtmlfile=gethtmlfile + "&sortid=" + sortidval
}
Else
{
Gethtmlfile=gethtmlfile + "sortid=" + sortidval
}
}
var Actionval=getthe_hrefvar ("Action");
if (actionval)
{
Gethtmlfile=gethtmlfile + "&action=" + actionval
}
var keywordval=getthe_hrefvar ("keywords");
if (keywordval)
{
Gethtmlfile=gethtmlfile + "&keywords=" + keywordval
}
Showajax_div ("Statusid", "Xweb-ajax-div", "Xweb-ajaxdiv", gethtmlfile,0);
-->
</script>

</body>

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.