2012-03-16 105 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

相关问题