JustinK101 Posted February 16, 2007 Share Posted February 16, 2007 So I have my php script, which is as follows: <?php require("pref.php"); require("db_connect.php"); if(!empty($_GET['customer_id']) && $_GET['customer_id'] != "None") { mysql_select_db("yjpalmer_ordermanager"); $sql = "SELECT order_id FROM orders WHERE associated_customer_id = " . $_GET['customer_id'] . " ORDER BY order_id ASC"; $result = mysql_query($sql); $myArray = array(); while($row = mysql_fetch_row($result)) { array_push($myArray, $row[0]); } print(json_encode($myArray)); } ?> A test output of the above script is: ["263","285","286","287","288","290","291","292","293","294"] Then my Javascript code is: function updateDependentSelectBox(serverSideScript, objectToRead, queryStringName, objectToAppend) { var the_obj; document.getElementById('ajax_status').innerHTML = '<img src="includes/ajax.gif" alt="Please Wait...">'; xmlHttp = createAjaxObject(); myValue = objectToRead.value; xmlHttp.open("GET", serverSideScript + '?' + queryStringName + '=' + myValue + '&sid=' + Math.floor(Math.random() * 1000000), false); xmlHttp.onreadystatechange=function() { if(xmlHttp.readyState==4) { if (xmlHttp.status == 200) { the_obj = eval("(" + xmlHttp.responseText + ")"); for(i = 0; i < the_obj.length; i++) { objectToAppend.options[objectToAppend.length] = new Option(the_obj[i], false, false); } setTimeout('document.getElementById(\'ajax_status\').innerHTML = \'\'', 850); } else { alert("AJAX Error! There Was A Problem Parsing The Following Server Side PHP Script.\n\n" + serverSideScript + ""); } } }; xmlHttp.send(null); } My problem is the following line: the_obj = eval("(" + xmlHttp.responseText + ")"); What does eval do? How is the variable the_obj constructed? How do I get my data out of it? Quote Link to comment Share on other sites More sharing options...
hitman6003 Posted February 17, 2007 Share Posted February 17, 2007 What does eval do? It executes the text passed to it as javascript. http://www.w3schools.com/jsref/jsref_eval.asp How is the variable the_obj constructed? It's defined at the beginning of execution: var the_obj; It is assigned a value of the result of the eval function. Then it is added as an option in a select box. How do I get my data out of it? This script that you are using will not do anything with JSON...it executes javascript returned from the server and appends the result to a select box option group. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.