Note that there are some explanatory texts on larger screens.

plurals
  1. POCan't get custom JSONP pipeline to work
    primarykey
    data
    text
    <p>I'm building an audio player that makes 3 different API calls, and I need them all to be in JSONP format, so I made a PHP proxy file that determines the output of the JSON data like so:</p> <pre><code>$datatype = $_GET["type"]; $artist = urlencode($_GET["artist"]); $album = urlencode($_GET["album"]); $content = ""; if($datatype == 'albumart'){ $content = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=album.getinfo&amp;api_key=037358e302c80571663e6a7a66b1dc05&amp;artist=' . $artist . '&amp;album=' . $album . '&amp;format=json'); } elseif($datatype == 'artistart'){ $content = file_get_contents('http://ws.audioscrobbler.com/2.0/?method=artist.getinfo&amp;api_key=037358e302c80571663e6a7a66b1dc05&amp;artist=' . $artist . '&amp;autocorrect=1&amp;format=json'); } else { $content = file_get_contents('http://cjzn.streamon.fm/metadata/recentevents/CJZN-48k.json'); } header('Content-type: application/json; charset=utf-8'); echo $_GET['callback'] . '(' . json_encode($content) . ')'; </code></pre> <p>Upon testing the output it seems to work fine, it gets the respective API data, wraps it in the JSONP <code>()</code> and accepts a JSONP callback.</p> <p>Bur when I try and use it in my Javascript file it doesn't seem to work, but I can't figure out why! Here's an example of one of the functions being used to call the JSON data:</p> <pre><code>function getAlbumArt(artist,album){ var dataArtist = artist, dataAlbum = album, albumArtURL; $.ajax({ url: 'jsonproxy.php', dataType: 'jsonp', data: { type: 'albumart', artist: dataArtist, album: dataAlbum }, success: function(data) { if(data.album.image[4]["#text"]){ var albumArtURL = data.album.image[4]["#text"]; $('section.player div.album-artwork').css({'background-image':'url("' + albumArtURL + '")'}); } else { getArtistArt(dataArtist); } }, error: function() { getArtistArt(dataArtist); alert('Sorry, unable to retrieve album artwork!'); } }); } </code></pre> <p>Can anyone help with why this doesn't work for me?</p> <p><strong>Edit</strong></p> <p>I did <code>alert(data);</code> on <code>success</code>, and that returned all of the data from the feed, after that if I did something more specific like <code>alert(data.album.image[4]["#text"]);</code> it returned <code>undefined</code>. Very confused here. Anyone have any thoughts?</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload