开发者

phonegap android ajax call not appending data

I'm new to phonegap and android. I am trying to create a project which fetch pages/data from webserver but it is not working. The code i have used is shown below, facing problem in appending data from ajax call.

when application starts in emulator it shows the alert with all data fetched from local server but its not appending to #resultBlock

here's my code

<!DOCTYPE HTML>
<html>
<head>
<title>PhoneGap</title>
<meta name="viewport" content="width=device-width, initial-scale=1"> 
        <link rel="stylesheet" href="jquery.mobile-1.0b3.min.css" />

    <script type="text/javascript" src="jquery.js"></script>
    <script type="text/javascript" src="jquery.mobile-1.0b3.min.js"></script>
<script type="text/javascript" charset="utf-8" src="phonegap-1.0.0.js"></script>
<script>


function onDeviceReady() {
    $('#resultBlock').html('Loading');
    $.ajax({
  url: 'http://192.168.1.2/user/welcome/',
  success: function(data) {
    $('#resultBlock').html(dat开发者_Go百科a);
    alert(data);
  }
});

}
$(document).ready(function() {
    document.addEventListener("deviceready", onDeviceReady, true);       
});

</script>
</head>
<body >
    <div data-role="page" id="page">
    <div data-role="header">
        <h1>Page One</h1>
    </div>
    <div data-role="content">   


        <h3>Result</h3>
        <p id="resultBlock"></p>

    </div>
    <div data-role="footer">
        <h4>Page Footer</h4>
    </div>
</div>

</body>
</html>

Thanks


hake sure the js files are included correctly and that the path is correct. then use

$(document).ready(function () {
 $.ajax({ 
                type: 'GET', 
                url: 'http://192.168.1.2/user/welcome/functions.php', 
                data: { get_param: 'candidates' },
                dataType:'json',
                success: function (data) { 
                     $('#resultBlock').html(data);
                                     alert(data);
                }, 
                error: function () { 
                    console.log(XMLHttpRequest.errorThrown); 
                } 

            });
});
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜