jquery ajax實現無重新整理資料載入代碼

來源:互聯網
上載者:User


<html xmlns="http://www.111cn.net/ 1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>

<script>
var xml_http_building_link = '請等待,正在建立串連...';
var xml_http_sending = '請等待,正在發送資料...';
var xml_http_loading = '請等待,正在接受資料...';
var xml_http_load_failed = '通訊失敗,請重新整理重新嘗試';
var xml_http_data_in_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 aj;
}
</script>

</head>

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

<script type="text/javascript教程" language="javascript">
                        <!--
                            var pageVal=getthe_hrefvar("page");
                            var getHtmlFile="../www.111cn.net/product_list.php教程";
                            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>
</html>

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.