2011-11-29 112 views
-2

有人帮我解决这个问题。我的ajax代码似乎不适用于IE8浏览器。它没有任何其他浏览器的问题。每次点击“显示我的钱”按钮后,其功能就是为“滑雪板已售出”和“斜坡现金:”带来动态值。为什么AJAX代码不能在IE8中工作?

来自随机值的代码是使用php生成的enter code here。我相信在代码中没有什么需要更改的,因为这是浏览器问题。

了AJAX代码如下:

<head> 
    <title>Boards 'R' Us</title> 
    <link rel="stylesheet" type="text/css" href="boards.css" /> 
    <script type="text/javascript" src="text-utils.js"> </script> 
    <script language="javascript" type="text/javascript"> 
    var request = null; 
//Declaring object for browsers 
    function createRequest() { 
    try { 
     request = new XMLHttpRequest(); 
    } catch (trymicrosoft) { 
     try { 
     request = new ActiveXObject("Msxml2.XMLHTTP"); 
     } catch (othermicrosoft) { 
     try { 
      request = new ActiveXObject("Microsoft.XMLHttp"); 
     } catch (failed) { 
      request = null; 
     } 
     } 
    } 

    if (request == null) 
     alert("Error creating request object!"); 
    } 

//function called on clicking show me the money button clicked 
    function getBoardsSold() { 
    createRequest(); 
    var url = "getUpdatedBoardSales-ajax.php"; 
    request.open("GET", url, true); 
    request.onreadystatechange = updatePage; 
    request.send(null); 
    } 

    function updatePage() { 
    if (request.readyState == 4) { 
     var newTotal = request.responseText; 
     var boardsSoldEl = document.getElementById("boards-sold"); 
     var cashEl = document.getElementById("cash"); 
     replaceText(boardsSoldEl, newTotal); 

     /* Figure out how much cash Katie has made */ 
     var priceEl = document.getElementById("price"); 
     var price = getText(priceEl); 
     var costEl = document.getElementById("cost"); 
     var cost = getText(costEl); 
     var cashPerBoard = price - cost; 
     var cash = cashPerBoard * newTotal; 

     /* Update the cash for the slopes on the form */ 
     cash = Math.round(cash * 100)/100; 
     replaceText(cashEl, cash); 
    } 
    } 
    </script> 
</head> 

<body> 
    <h1>Boards 'R' Us :: Custom Boards Report</h1> 
    <div id="boards"> 
    <table> 
    <tr><th>Snowboards Sold</th> 
    <td><span id="boards-sold">1012</span></td></tr> 
    <tr><th>What I Sell 'em For</th> 
    <td>$<span id="price">249.95</span></td></tr> 
    <tr><th>What it Costs Me</th> 
    <td>$<span id="cost">84.22</span></td></tr> 
    </table> 
    <h2>Cash for the Slopes: 
    $<span id="cash">167718.76</span></h2> 
    <form method="GET"> 
    <input value="Show Me the Money" type="button" 
      onClick="getBoardsSold();" /> 
    </form> 
    </div> 
</body> 
</html> 
+1

你会得到什么错误?什么不工作? –

+1

如何开始使用像jQuery这样的JavaScript库,这使得你更容易为dom遍历,ajax处理等...?www.jquery.com – Shyju

+0

在我的编程生涯中,我曾经手工编码的一切。我已经达到了那里有太多浏览器的地步。 JQuery是要走的路... – Frank

回答