- Query string parameters from Javascript do not make it to processing PHP script
- <div id="ListBox">
- <script type="text/javascript">
- popList("name", "categories");
- </script>
- </div>
- function popList(field, table) {
- $.ajax({
- type: "GET",
- url: 'getListOfValues.php',
- data: 'field='+escape(field)+'&table='+escape(table),
- dataType: 'json',
- success: function(response) {
- var source = $.parseJSON(response);
- $("#ListBox").jqxListBox({ source: source, checkboxes: true, width: '400px', height: '150px', theme: 'summer'});
- },
- error: function() {
- alert('sources unavailable');
- }
- });
- }
- <?php
- require "dbinfo.php";
- // Opens a connection to a MySQL server
- $connection=mysql_connect($host, $username, $password);
- if (!$connection) {
- die('Not connected : ' . mysql_error());
- }
- // Set the active MySQL database
- $db_selected = mysql_select_db($database, $connection);
- if (!$db_selected) {
- die ('Can't use db : ' . mysql_error());
- }
- $field = $_GET["field"];
- $table = $_GET["table"];
- $field = mysql_real_escape_string($field);
- $table = mysql_real_escape_string($table);
- $qryString = "SELECT " . $field . " FROM " . $table;
- $qryResult = mysql_query($qryString) or die(mysql_error());
- $source = array();
- while ($row = mysql_fetch_array($qryResult)){
- array_push($source, $row[$field]);
- }
- mysql_close($connection);
- echo json_encode($source);
- ?>
- ajaxRequest.onreadystatechange = processAjaxResponse;
- function processAjaxResponse() {
- if (ajaxRequest.readySTate == 4) {
- var response = ajaxRequest.responseText;
- //do something with the response
- //if you want to decode the JSON returned from PHP use this line
- var arr = eval(response);
- }
- }
- print json_encode($listOfReturnedValues);
- function popList(field,table) {
- $.ajax({
- type: "GET",
- url: 'getListofValues.php',
- data: 'field='+escape(field)+'&table='+escape(table),
- dataType: "json",
- success: function(response) {
- //the response variable here would have your array automatically decoded
- }
- });
- }