Satch3000
Satch3000

Reputation: 49422

getJSON works on Android but Not IOS

I am testing getting some json and the json code actually shows on my Android but when I try it on my iPhone it won't work.

Is there anything extra that needs setting for IOS ?

Here is the code:

<!DOCTYPE html> 
<html> 
    <head> 
    <title>JSON Test</title>
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <link rel="stylesheet" href="css/jquery.mobile-1.1.1.min.css" />
    <script src="js/jquery-1.7.1.min.js"></script>
<script>
    $('#page1').live("pageinit", function () {
        $.getJSON("http://mysite.com/api/get_cats", function (data) {
            var output = '';    
            $.each(data.cats, function (index, value) {
                output += '<li>' + value.title + '</li>';    
            });
            $('#listview').append(output).listview('refresh');
        });
    });
</script>
<script src="js/jquery.mobile-1.1.1.min.js"></script>

</head> 
<body>     
<div id="page1" data-role="page">    
    <div data-role="header">
        <h1>Page Title</h1>
    </div><!-- /header -->    
    <div data-role="content">   
        <p>Page content goes here.</p>              
        <ul id="listview"></ul>             
    </div><!-- /content -->    
    <div data-role="footer">
        <h4>Page Footer</h4>
    </div><!-- /footer -->
</div><!-- /page -->    
</body>
</html>

If I add an alert: alert(data.cats); I get "index.html [object: Object]" in the iphone"

Any ideas anyone?

Upvotes: 0

Views: 1099

Answers (1)

Krym
Krym

Reputation: 743

Do you have that domain whitelisted ?

It's in config.plist...while on android it's in cordova.xml

See http://docs.phonegap.com/en/2.0.0/guide_whitelist_index.md.html#Domain%20Whitelist%20Guide

EDIT: You can alert things from respons jqxhr object as well to find out more. As a response function add another two parameters

    function(data, textStatus, jqXHR){...}

Upvotes: 4

Related Questions