Mansa
Mansa

Reputation: 2325

Trying to populate listview with json

I am trying to make an golf app/webapp in which i can find my upcoming matches from a listview... but.

If I want to make it an app I need to populate my listview using json. I'm a bit new to this but have tried it like this:

My json data looks like this:

[{"season":"OOM '09","course":null,"matchform":"Stableford"},{"season":"OOM '10","course":null,"matchform":"strokeplay"},{"season":"OOM '10","course":null,"matchform":"Stableford"}]

Here is how I try to get it:

$(document).ready(function(){   
    $.getJSON("http://appdata.golfacross.com/TEST_matches.php",          
              function(data){
                  var content = []
                  $.each(data , function(i,val){
                      content.push("<li>");
                      content.push("<h3>" + val.season + "</h3>");
                      content.push("<p>" + val.matchform + "</p>");
                      content.push("</li>");   
                  });
                  $("#mathes_list_count").html(content.join(""));
              });
});

And here is my html:

<div data-role="page" id="matches" data-theme="a">

      <div data-role="header" data-position="inline" data-theme="a">
         <h1>upcoming matches</h1>
      </div>

      <div data-role="content" id="matcheslist">

          <ul data-role='listview' id="mathes_list_count"></ul>

      </div>

</div>

I don't get any result :-/ Don't know if I am doing this right and any help is apreciated. I have created a jsfiddle project: http://jsfiddle.net/jmansa/r88t7/

Hoping for help and thanks in advance :-)

Upvotes: 0

Views: 86

Answers (1)

Twisted1919
Twisted1919

Reputation: 2499

You cannot make a remote ajax request, what you need is jsonp by appending a callback to your request url, something like:

    $.getJSON('http://appdata.golfacross.com/TEST_matches.php?callback=?', {data:'here'}, function(o){

});

But that remote host should accept jsonp calls in order to return your data.

If it doesn't support jsonp, then just create a php script on your host, use curl to fetch the data from the remote host, and from jquery, instead of query the remote host, query your local php file that will do the curl request and return the json objects.

Upvotes: 1

Related Questions