I'm trying to load database info but it doesn't seem to be working in JSFiddle.
HTML:
<table class="table" border="1" cellpadding="0" cellspacing="0">
<thead>
<tr>
<th>Dropdown</th><th>Description From Account</th><th>Other</th>
</tr>
</thead>
<tbody>
<tr>
<td width="20%" id="accountNumber" contenteditable="true"><select data-placeholder="Choose Account . . ." class="chosen-select-newRow" style="width:350px;" tabindex="4"><option value=""></option></select></td><td id="accountDesc" contenteditable="true"></td><td id="branch" contenteditable></td>
</tr>
<tr>
<td width="20%" id="accountNumber" contenteditable="true"><select data-placeholder="Choose Account . . ." class="chosen-select-newRow" style="width:350px;" tabindex="4"><option value=""></option></select></td><td id="accountDesc" contenteditable="true"></td><td id="branch" contenteditable></td>
</tr>
</tbody>
</table>
Ajax:
function populate(){
$(function ()
{
//-----------------------------------------------------------------------
// 2) Send a http request with AJAX http://api.jquery.com/jQuery.ajax/
//-----------------------------------------------------------------------
$.ajax({
url: 'journal-populate.php', //the script to call to get data
data: '', //you can insert url argumnets here to pass to api.php
//for example "id=5&parent=6"
dataType: 'json', //data format
success: function(rows){
for (var i in rows)
{
var row = rows[i];
//var account = row[1]; //get id
//var description = row[2]; //get account description
$('.chosen-select-newRow').append($('<option></option>').val('?acc=' + row[1] + '&desc=' + row[2]).html(row[1] + ' - ' + row[2]));
//alert(id + ' ' + account + ' ' + description + ' ' + level1 + ' ' + level2 + ' ' + level3 + ' ' + level4 ); /*'<span onclick="return false;" href="?account='+ row[1] +'&desc='+ row[2] +'">'+*/ /*+'</span>'*/
}
}
});
});
}
PHP:
<?php
include('dbconn.php');
//--------------------------------------------------------------------------
// Example php script for fetching data from mysql database
//--------------------------------------------------------------------------
$databaseName = "mochamhy_test";
$tableName = "accountMaster";
//--------------------------------------------------------------------------
// 1) Connect to mysql database
//--------------------------------------------------------------------------
$con = mysql_connect($gaSql['server'],$gaSql['user'],$gaSql['password']);
$dbs = mysql_select_db($databaseName, $con);
//--------------------------------------------------------------------------
// 2) Query database for data
//--------------------------------------------------------------------------
$result = mysql_query("SELECT * FROM $tableName ORDER BY `accountNumber` ASC"); //query
//$array = mysql_fetch_array($result); //fetch result
$data = array();
while ( $row = mysql_fetch_row($result) )
{
$data[] = $row;
}
//--------------------------------------------------------------------------
// 3) echo result as json
//--------------------------------------------------------------------------
echo json_encode($data);
?>
It's working on my localhost, but I can't seem to get it working on a Fiddle. I can even see the JSON data here http://www.mochamedia.co.za/clients/testing/js/journal-populate.php
I don't know if it's possible?
Any help or suggestions will be appreciated!