0

I'm trying to display some information from a json object. My getJson function doesn't return anything.

I think the problem is that i don't target the right value.

My code:

<div id="content" class="clearfix row">
    <div class="col-md-6">
    <p>Please enter your searchterm:</p>
    <input id="myinput" type="text">
</div>

<div class="col-md-6" id="result">

</div>

jQuery(document).ready(function() {
    jQuery.getJSON("http://ghost-app.com/api/search?searchterm=pro_wheely",function(data){
        jQuery("#result").prepend('<h3>'+data.players.results[0].username+'</h3>');
    });
});

I can view the json file just fine in my browser. JSON link

As far as i can tell everything looks right. Any suggestions?

Karsten Tietje
  • 259
  • 2
  • 4
  • 15
  • 1
    Javascript has a same-origin policy, and you've just discovered how it's works. You can't get JSON from a cross domain site that doesn't send certain headers or support JSONP, it just can't be done. – adeneo Jul 22 '14 at 21:42
  • Anything I can do about that? – Karsten Tietje Jul 22 '14 at 21:43
  • 1
    [Ways to circumvent the same-origin policy](http://stackoverflow.com/questions/3076414/ways-to-circumvent-the-same-origin-policy) has some Ajax-specific tips – apsillers Jul 22 '14 at 21:46
  • Unless you can change the settings on the API you're contacting, no! You can get the data with serverside code, and then do the ajax call to your own server. – adeneo Jul 22 '14 at 21:46
  • Sounds like too much work for the kind of project i was thinking about. It's an unofficial API anyway so could be taken down any day. Too bad they didn't include a way to retrieve data from cross-domain. I've tried adding `?callback=?` to the url without luck.Thx for the help anyway- – Karsten Tietje Jul 22 '14 at 21:51

0 Answers0