2013-03-27 17 views
0

我有這段代碼。它獲取請求數據並使用刷新將其顯示在DIV中。AJAX請求沒有樣式的jQuery鏈接

爲什麼它顯示要求像「簡單文本」數據,DIV,但無法顯示,例如這條線:

<a href="#" data-role="button">Button</a> 

與應用/ CSS渲染和jQuery.mobile按鈕樣式?我錯過了什麼嗎?

<!DOCTYPE html> 
<html> 
    <head> 
    <link rel="stylesheet" href="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.css"> 
    <script src="http://code.jquery.com/jquery-1.9.1.min.js"></script> 
    <script src="http://code.jquery.com/mobile/1.3.0/jquery.mobile-1.3.0.min.js"></script> 
    <script> 
     function GetData() 
     { 
     nocache = "&nocache=" + Math.random() * 1000000; 
     var request = new XMLHttpRequest(); 
     request.onreadystatechange = function() 
     { 
      if (this.readyState == 4) { 
      if (this.status == 200) { 
       if (this.responseText != null) { 
       document.getElementById("buttons").innerHTML = this.responseText; 
       } 
      } 
      } 
     } 
     request.open("GET", "state" + nocache, true); 
     request.send(null); 
     setTimeout('GetData()', 1000); 
     } 
    </script> 
    </head> 
    <body onload="GetData()"> 
    <div id="buttons" data-role="content"> 
    </div> 
    </body> 
</html> 

回答

1

替換此document.getElementById("buttons").innerHTML = this.responseText;

$("#buttons").html(this.responseText); 

這就是我做的。

而且,看到你正在使用jQuery你可以替換與檢查準備狀態等處理與$(function(){ //your code here });

您還可以再用<body onload="GetDate()">做掉,只是有<body>你的代碼的很大一部分。