i am having two tables tbl_category, tbl_food. I am using Cordova so i use a html file, a remote .php file and i want to select all from the tbl_food where the category is "ID" (can be 1 or 2 or 3...).
I use the following code for the php file:
<?php
include "db.php";
if(isset($_POST['check']))
{
$ID=$_POST['ID'];
$data=array();
$q=mysql_query("select * from `tbl_food` WHERE Cat='$ID'");
while ($row=mysql_fetch_assoc($q)){
$data[]=$row;
echo json_encode($data);
}
}
?>
and this is the ajax code i am using into the HTML file, the function will be called once i select the category from the dropdown:
function getFoodList() {
var ID = $('#foodcat :selected').val();
var dataString = "&ID=" + ID + "&check=";
$.ajax({
type: "POST",
url: "http://myurl.com/load_list.php",
data: dataString,
dataType: 'json',
crossDomain: true,
cache: false,
success: function (data) {
var result=$.parseJSON(data);
$.each(result, function (index, val) {
$("#foodlist").append($('<option></option>').val(val.Points).html(val.Name) + " - " + val.Quantity);
});
}
});
}
The problem is it never reaches the success function: which means if i am not wrong, that the php doesn't return anything.