View Single Post
Old 03-23-2006, 07:14 PM   #2 (permalink)
sde
Moderator
 
sde's Avatar
 
Join Date: May 2002
Location: us.ca
Posts: 4,505
sde is on a distinguished road
i have json installed on the server. you can convert a php to a javascript array string by using this:
PHP Code:
<?
$array 
= array('apple''orange''pear');
echo 
json_encode($array);
?>
then u can use some ajax stuff like this:
HTML Code:
<script>
// start ajax stuff
var xmlHttp;

function createXMLHttpRequest() {
	if (window.ActiveXObject) {
		xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
	}
	else if (window.XMLHttpRequest) {
		xmlHttp = new XMLHttpRequest();
	}
}

function startRequest(method, URL) {
	createXMLHttpRequest();
	xmlHttp.onreadystatechange = handleStateChange;
	xmlHttp.open(method, URL, true);
	xmlHttp.send(null);
}

function handleStateChange() {
	if (xmlHttp.readyState == 4) {
		if (xmlHttp.status == 200) {
			processResponse(xmlHttp.responseText);
		}
	}
}

function processResponse(response) {
	my_songs = eval(response);

}
// end ajax stuff

// initialize your song array
var my_songs;

// make ajax request
startRequest('GET', 'my_php_script.php');

// now my_songs is set to your php array
</script>
sde is offline   Reply With Quote