SitePoint Sponsor

User Tag List

Results 1 to 2 of 2

Hybrid View

  1. #1
    SitePoint Zealot
    Join Date
    May 2008
    Posts
    165
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    jQuery JSON Fetch

    I am having some trouble fetching some JSON data from a certain feed, namely: http://www.bbc.co.uk/radio1/nowplaying/latest.json
    When downloading the contents of the file manually and using it locally, there are no problems, so I can rule out the structuring of the document.

    However, calling this in jQuery:
    Code JavaScript:
    $.getJSON('http://www.bbc.co.uk/radio1/nowplaying/latest.json').error(function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.statusText);
    });
    returns the text 'error' with the status code of 0. Could somebody either, a) verify the results I'm getting or b) suggest where I'm going wrong!

  2. #2
    SitePoint Enthusiast
    Join Date
    Aug 2010
    Location
    Perundurai, Tamilnadu, India
    Posts
    72
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Directly you can't call different server thru AJAX. To solve this problem.

    $.getJSON('test.php').error(function(XMLHttpRequest, textStatus, errorThrown) { alert(XMLHttpRequest.statusText);
    });
    Create test.php in your server, use cURL to retrieve the data from bbc.co.uk and just print it.

    <?php
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_URL, "http://www.bbc.co.uk/radio1/nowplaying/latest.json");
    curl_setopt($ch, CURLOPT_HEADER, 0);
    curl_exec($ch);
    curl_close($ch);
    ?>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •