<tfoot id='jDp1o'></tfoot>
<i id='jDp1o'><tr id='jDp1o'><dt id='jDp1o'><q id='jDp1o'><span id='jDp1o'><b id='jDp1o'><form id='jDp1o'><ins id='jDp1o'></ins><ul id='jDp1o'></ul><sub id='jDp1o'></sub></form><legend id='jDp1o'></legend><bdo id='jDp1o'><pre id='jDp1o'><center id='jDp1o'></center></pre></bdo></b><th id='jDp1o'></th></span></q></dt></tr></i><div id='jDp1o'><tfoot id='jDp1o'></tfoot><dl id='jDp1o'><fieldset id='jDp1o'></fieldset></dl></div>

    <bdo id='jDp1o'></bdo><ul id='jDp1o'></ul>

<small id='jDp1o'></small><noframes id='jDp1o'>

    <legend id='jDp1o'><style id='jDp1o'><dir id='jDp1o'><q id='jDp1o'></q></dir></style></legend>

      1. XMLHttpRequest 在 IE 7/8 中不起作用,但在其他浏览器中起作用

        时间:2024-08-10

            <i id='2DFYH'><tr id='2DFYH'><dt id='2DFYH'><q id='2DFYH'><span id='2DFYH'><b id='2DFYH'><form id='2DFYH'><ins id='2DFYH'></ins><ul id='2DFYH'></ul><sub id='2DFYH'></sub></form><legend id='2DFYH'></legend><bdo id='2DFYH'><pre id='2DFYH'><center id='2DFYH'></center></pre></bdo></b><th id='2DFYH'></th></span></q></dt></tr></i><div id='2DFYH'><tfoot id='2DFYH'></tfoot><dl id='2DFYH'><fieldset id='2DFYH'></fieldset></dl></div>
          • <legend id='2DFYH'><style id='2DFYH'><dir id='2DFYH'><q id='2DFYH'></q></dir></style></legend>
            1. <tfoot id='2DFYH'></tfoot>

                <tbody id='2DFYH'></tbody>

              <small id='2DFYH'></small><noframes id='2DFYH'>

                • <bdo id='2DFYH'></bdo><ul id='2DFYH'></ul>
                • 本文介绍了XMLHttpRequest 在 IE 7/8 中不起作用,但在其他浏览器中起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我开发了一个在 chrome 和 firefox 上运行良好的网络应用程序.但是,当涉及到测试时间时,它在 IE 中无法正常工作.它似乎并没有真正得到请求?

                  I've developed a web application that works well on chrome and firefox. However when it came to testing time and it doesn't work properly in IE. It just doesn't seem to actually get the request?

                  这里是 Javascript 代码:

                  here's the Javascript code:

                  function createXMLHttpRequest() {
                      var xmlhttp = false;
                      if (window.XMLHttpRequest) {
                          xmlhttp = new XMLHttpRequest();
                      } else if(window.ActiveXObject) {
                          try {
                              xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
                          } catch (e) {
                              try {
                                  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                              } catch (e) {
                                  xmlhttp = false;
                              }
                          }
                      }
                      return xmlhttp;
                  };
                  
                  
                  
                  
                  function checkForData(){
                  
                      var target = document.getElementById('accordion');
                      var loading = document.getElementById('controls');
                  
                      var xhr = createXMLHttpRequest();
                  
                  
                      loading.innerHTML = '<img src="../images/loading.gif" width=20 height=20 />Querying the Database';
                  
                      xhr.open('GET','getData.php',true);
                      xhr.send(null); 
                  
                      xhr.onload = function(){
                          loading.innerHTML = '<a href="../classes/php/print.php" />Print Report</a><br/><br/><a href="../index.php" />HomePage</a><br/><a href="../classes/php/actionedClass.php" />Refresh</a><br/><a href="../classes/php/logout.php" />Logout</a><br/>';
                  
                          target.innerHTML = xhr.responseText;
                  //      addPrettyness();
                  
                      };
                      xhr.onerror = function (){
                          target.innerHTML = 'Failed :(';
                      };
                  
                  }
                  
                  function addPrettyness(){
                      $(function() {
                                      var stop = false;
                                      $( "#accordion h3" ).click(function( event ) {
                                          if ( stop ) {
                                              event.stopImmediatePropagation();
                                              event.preventDefault();
                                              stop = false;
                                          }
                                      });
                                      $( "#accordion" )
                                              .accordion({
                                                  collapsible: true,
                                                  header: "> div > h3"});
                      });
                  }
                  
                  function checkAgain(){
                      setInterval('checkForData()',30000);            //Every 30 seconds run the check for new data script
                  
                  }
                  
                  
                  function changeAction(action, actionChangeId){
                  
                      xhr = new XMLHttpRequest();
                  
                      if(action == 0){
                  
                  
                          var loading = document.getElementById('controls');
                          loading.innerHTML = '<img src="../images/loading.gif" width=20 height=20 />Sending to the Database';        
                  
                          xhr.open('GET','../classes/php/actionNo.php?actionChangeId='+actionChangeId,true);
                          xhr.send();
                  
                          xhr.onload = function(){
                              checkForData();
                          };
                  
                          xhr.onerror = function(){
                              alert('Failed to change action... Try again please!');
                          };
                  
                      }else if(action == 1){
                          xhr = new XMLHttpRequest();
                  
                          var loading = document.getElementById('controls');
                          loading.innerHTML = '<img src="../images/loading.gif" width=20 height=20 />Sending to the Database';        
                  
                  
                          xhr.open('GET','../classes/php/actionYes.php?actionChangeId='+actionChangeId,true);
                          xhr.send();
                  
                          xhr.onload = function(){
                              checkForData();
                          };
                  
                          xhr.onerror = function(){
                              alert('Failed to change action... Try again please!');
                          };
                      }
                  }
                  
                  function startEngine(){
                      checkForData();
                      //checkAgain();
                  
                  }
                  
                  
                  window.onload = startEngine;
                  

                  它从 echos 请求的 .php 文件将字符串结果返回给 javascript.

                  and the .php file it requests from echos back a string result to the javascript.

                  推荐答案

                  如前所述这里, Internet Explorer 仅从版本 9 开始支持 XMLHttpRequest 对象的 onload 事件.

                  As mentioned here, Internet Explorer supports the onload event of the XMLHttpRequest object only since version 9.

                  所以,对于 IE 8 及以下版本,你可以用老式的方式来做:

                  So, for IE 8 and below, you can do it in the old fashioned way:

                  xhr.onreadystatechange = function()
                  {
                      //ready?
                      if (xhr.readyState != 4)
                          return false;
                  
                      //get status:
                      var status = xhr.status;
                  
                      //maybe not successful?
                      if (status != 200) {
                          alert("AJAX: server status " + status);
                          return false;
                      }
                  
                      //Got result. All is good.
                      loading.innerHTML = '<a href="../classes/php/print.php" />Print Report</a>' + 
                          '<br/><br/><a href="../index.php" />HomePage</a><br/>' + 
                          '<a href="../classes/php/actionedClass.php" />Refresh</a><br/>' + 
                          '<a href="../classes/php/logout.php" />Logout</a><br/>';
                      target.innerHTML = xhr.responseText;
                  
                      return true;
                  }
                  

                  这篇关于XMLHttpRequest 在 IE 7/8 中不起作用,但在其他浏览器中起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  上一篇:取消 PHP 应用程序中未决的 AJAX 请求? 下一篇:使用 javascript 和 XMLHTTPRequest 将 FormData 发布到 php

                  相关文章

                  <small id='nmd0d'></small><noframes id='nmd0d'>

                      <tfoot id='nmd0d'></tfoot>
                      <i id='nmd0d'><tr id='nmd0d'><dt id='nmd0d'><q id='nmd0d'><span id='nmd0d'><b id='nmd0d'><form id='nmd0d'><ins id='nmd0d'></ins><ul id='nmd0d'></ul><sub id='nmd0d'></sub></form><legend id='nmd0d'></legend><bdo id='nmd0d'><pre id='nmd0d'><center id='nmd0d'></center></pre></bdo></b><th id='nmd0d'></th></span></q></dt></tr></i><div id='nmd0d'><tfoot id='nmd0d'></tfoot><dl id='nmd0d'><fieldset id='nmd0d'></fieldset></dl></div>
                        <bdo id='nmd0d'></bdo><ul id='nmd0d'></ul>
                    1. <legend id='nmd0d'><style id='nmd0d'><dir id='nmd0d'><q id='nmd0d'></q></dir></style></legend>