I have an AJAX statement that is meant to return echoed output from a PHP script the output is XML.
If navigate directly to the PHP script it outputs the JSON in the exact format I need.
the “data” variable in the AJAX request is not returning it properly, even though firebug network tab says status 200 ok for request.
The PHP returning XML elements “MP3 and Title”
<?php
$url = 'http://www.startalkradio.net/?page_id=354';
$rss = simplexml_load_file($url);
$items = $rss->channel->item;
$i = 0;
$data = array();
foreach ($items as $item) {
$data[] = array(
'title' => (string) $item->title,
'mp3' => (string) $item->enclosure['url'],
);
if (++$i == 3) break;
}
$jsdata = json_encode($data);
echo htmlspecialchars($jsdata, ENT_NOQUOTES, 'utf-8');
?>
AJAX call populating JPlayer script. data does not seem to be returned.
$(document).ready(function() {
$.get(
"http://www.freeenergymedia.com/getxml2.php",
function(data) {
new jPlayerPlaylist({
jPlayer: "#jquery_jplayer_1",
cssSelectorAncestor: "#jp_container_1"
},
data,
{ <!-- here I am returning the php script to populate XML into JPlayer. -->
swfPath: "js",
supplied: "mp3, oga",
wmode: "window"
});
}
);
});
the link in question
Here is a version that works note that the XML is the same as what is output by the PHP script
link
You say that you are returning XML but your PHP uses
json_encode(). So your$.get()call should specify that:datashould look something like this: