2013-10-09 49 views
0

我想在android phonegap的listview中顯示來自servlet的json數據。但它在android模擬器中顯示空白頁面。它也不會調用servlet。這裏是我的代碼,請幫助我。從android servlet中將數據加載到listview中獲取blankpage

<!DOCTYPE HTML> 
    <html> 

<head> 
<meta name="viewport" content="width=320; user-scalable=no" /> 
<meta http-equiv="Content-type" content="text/html; charset=utf-8"> 
<title>Auth Demo</title> 
<link rel="stylesheet" href="jquery.mobile-1.3.2.css" type="text/css" charset="utf-8" /> 
<script type="text/javascript" src="jquery.mobile-1.3.2.min.js"></script> 
<script type="text/javascript" charset="utf-8" src="cordova.js"></script> 
<script src="jquery-1.9.1.js"></script> 
<script src="jquery.mobile-1.3.2.js"></script> 

<script> 
$.ajax({ 
url: 'http://10.0.2.2:7080/example/CaseList', 
dataType: 'jsonp', 
jsonp: 'jsoncallback', 
timeout: 5000, 
success: function(data, status){ 
    $.each(data, function(i, item) { 
      $('ul').append('<li><a href="">' + item.case + '</a></li>'); 
      }); 

    $('#output').listview("refresh"); 
}, 
error: function(){ 
    output.text('There was an error loading the data.'); 
} 
    }); 
</script> 
</head> 

<body> 
<div data-role="page"> 
<div data-role="content">  
    <ul data-role="listview" data-filter="false" id="output" data-theme="d"> 
    </ul> 
</div> 
</div> 
</body> 
</html> 

回答

0

我對Ajax調用不是100%了,但我敢肯定,你需要實際調用該函數定義它,它看起來並不像你之後。

嘗試在你的標籤中加入一個onload調用,然後在你的函數中包裝你的ajax。

身體標記:

<body onload="getData()"> 

功能:

function getData(){ 
    //place your ajax call in here 
} 
+0

我試圖把onload事件呼叫,但它不工作 – sirisha

相關問題