2013-10-09 53 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

相关问题