Is this possible:
I am using an Ajax call to grab some results of a SQL query. The results are returns in an array which I echo as JSON at the end of a PHP script (which the ajax calls).
Then for each row of the sql result I am using 'append' to add an option to an html select as follows:
$.ajax({
type: "POST",
dataType: "json",
url: "DoSQL.php",
data: dataString,
success:function(reply){
$.each(reply, function(x, row){
$('#mySel').append($('<option>', {value: row, text:'Some text'}));
});
});
As you can see I am giving the value of the select option an array. Then I am detecting when the select is changed, but the value is returned as an object. Can I pass the array as the value and if so how do I access its contents:
$("#mySel").change(function(){
var result=$('#matchSel').val();
alert(result);
})
Thanks in advance,
Alan.
EDIT: 'fixture' was an error, it should be 'row'. I have corrected my example code above. I'm trying to return the result of the mysql query to the html select.
EDIT: Here is the PHP code as requesteD:
$query="SELECT * FROM `table1`";
$result=$mysqli->query($query);
while($row=$result->fetch_array(MYSQLI_ASSOC)){
$res[]=$row;
}
$mysqli->close();
echo json_encode($res);
So the array $res is what is returned as reply and then assigned to row
optionvalue?