Hello all,

I need some help on using prototypes Ajax.Updater with data from a php file.

Basically I need to update the content of an html form element AND obtain the value of a single php variable after the ajax update has completed.

I've been able to update the content of the html form but I can't figure out how to retrieve the php variables data from within the javascript function.

Here is the simple javascript function getNewSong(). This function populates the html form correctly with data from the php form. But I've added a variable 'unknownName' that I need to populate from the php file that I call.

function getNewSong() {
var unknownName;
var url = '/Scripts/load_song.php';
var myAjax = new Ajax.Updater(
failure: 'errors'
method: 'get',
onSuccess: function(transport) { unknownName = ???? },

return unknownName;

Now here is an example of the php file load_song.php
echo 'Lots of data that is populated into the html form';

// I need this file name within the javascript function
$file_name = getFileNameFromDb();
return $file_name;

Does anyone know how I can retrieve the data from the php variable $file_name in the js function after it has successfully completed? All I seem to be able to access is the data that is echoed by the php file and populated within the form.

Any help is much appreciated.