PhoneGap的Andr​​oid版的getJSON

问题描述:

我要带我的第一个步骤的PhoneGap的Andr​​oid(为什么你必须选择一个平台啊?这应该是跨平台的!)。我想打电话给RESTful服务,作为回报获得一些JSON,并把它在屏幕上。这个教程是令人难以置信的很难找到。我用下面的code:

I'm taking my first steps in PhoneGap with Android (How come you have to pick a platform, anyway? It's supposed to be cross-platform!). I'm trying to call a RESTful service, get some JSON in return and put it on the screen. Tutorials for this are incredibly hard to find. I'm using the following code:

<!DOCTYPE HTML>
<html>
<head>
        <title>JSON Demo</title>
        <script type="text/javascript" src="jquery.js"></script>
        <script type="text/javascript" src="jquery-1.6.4.js"></script>

        <script type="text/javascript">

$.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?',  {
    success:function(data)
    {
            data = evalJSON(data);
            $('body').append('<strong>X </strong>');
    }, 
    error: function() 
    {
     $('body').append('<strong>Error </strong>'); 
    }
});
        </script>
</head>
<body>
test 10
</body>
</html>

...但是,我没有得到响应,既不成功也不是错误。服务器报告已经打不过,而返回的数据。浏览相同的URL也返回的数据。为什么没有出现在模拟器?

...But I get no response, neither success nor error. The server reports that it has been hit though, and returned the data. Browsing to the same URL also returns data. How come nothing appears in the emulator?

由于某些原因的成功:与错误:被杀死它,也就是这个作品:

For some reason the success: and error: were killing it, ie this works:

     <script type="text/javascript">

$.getJSON('http://MyServerIP/json/GetJobDetails/717/MyKey?callback=?', function(data)
    {
            data = evalJSON(data);
            $('body').append('<strong>X </strong>');        
});
        </script>