2012-03-16 109 views
0

我想重定向我的getJSON響應低於另一個HTML頁面是兩個HTMLS的getJSON響應重定向到另一個HTML頁面

的index.html

$(document).ready(function() { 
alert("load"); 
    $.getJSON("http://10.0.2.2:8080v1/service/26/1", 
    function(data) { //want to redirect this response display.html 
    $.each(data, function(id, obj){ 
      $.each(obj, function(propName, value){ 
       // console.log(propName + ": " + value); 
       alert("propName: "+propName+" value: "+value); 
      }); 
     }); 


    }); 

    document.addEventListener("deviceready", onDeviceReady, true); 

}); 

function onDeviceReady(){ 
    navigator.notification.alert("PhoneGap is working"); 

} 

</script> 

</head> 
<body> 

</body> 
</html> 

display.html

在代碼這我有代碼以表格的形式顯示響應數據。你能幫我現在如何發送的getJSON響應display.html並在此

 <body> 
    <table width="100%" cellspacing="3"> 
     <tr align="center"> 
     <td bgcolor="#474646" style="color: #fff; >first column</td> 
     <td bgcolor="#474646" style="color: #fff; >second column</td> 
     <td bgcolor="#474646" style="color: #fff; >third column</td> 

     </tr> 
     <tr align="center"> 
     <td>firstcolumn</td> 
     <td>secondcolumn</td> 
     <td>thirdcolumn</td> 
     </tr> 
     </table> 

    </body> 
+0

你爲什麼不在display.html中做'getJson'? – 2012-03-16 15:07:12

+0

你能說我哦如何顯示在表中的響應,如果我寫在display.html的getjson – user1265530 2012-03-16 18:43:02

回答

0

你的意思是你想完成重定向的頁面display.htm一旦你的getJSON使用?如果是這樣,請試試這個:

$.getJSON("http://10.0.2.2:8080v1/service/26/1", 
    function(data) { 
    window.location = "display.html"; 
}); 

此外,它看起來像你的網址格式不正確。我認爲你缺少一個「/」前的「V1」,因此,它應該是這樣的「http://10.0.2.2:8080/v1/service/26/1」

編輯:

從你的評論,這聽起來像你只是想將display.html的內容加載到index.html的主體。如果是這樣,我不認爲你想使用getJSON,我想你只是想'加載'見下文。

<script type="text/javascript"> 
    $(document).ready(function() { 
     alert("load"); 
     $('#someDiv').load('display.html'); 
     document.addEventListener("deviceready", onDeviceReady, true); 
    }); 
</script> 
<body> 
    <div id='someDiv'></div> 
</body> 

請確保您獲取display.htm正確的路徑。

+0

我得到03-16 18:05:53.908:E /鉻(576):外部/鉻/網絡/磁盤緩存/ backend_impl .cc:1107:[0316/180553:ERROR:backend_impl.cc(1107)]發現嚴重錯誤-8 – user1265530 2012-03-16 18:18:08

+0

有人會說我如何從index.html獲取響應並在display.html表中打印 – user1265530 2012-03-16 18:19:14

+0

如果您是仍然有這個問題,讓我們知道。請嘗試儘可能詳細地解釋你的情況。 – davehale23 2012-03-19 19:43:45

相關問題