我知道这个问题已被多次询问,但我已经尝试了几个小时但没有任何效果,我是一个用PHP和ajax的菜鸟,所以,我可能会错过一个我不知道的小事,我是什么的试图在这里实现的是,我希望用户选择一个食物组,并根据该组成一系列成分.
我单独测试了我的process.php文件,它运行良好,我还测试了脚本会发生什么,当我将它注释掉并键入alert(parent)时,从$.ajax开始的行不起作用我实际上得到了选择的选项的价值,所以我在这里做错了什么?或者我错过了一个导入?
P.S我正在使用bootstrap 3.0进行设计
这是我的HTML代码
Food Group *
// retreiving the recipe groups
$RecipeGroup = new FoodGroup();
$data = $RecipeGroup->findAll();
foreach ($data->results() as $recipegroup) {
// displaying the options
echo ''.$recipegroup->food_group_name.'';
}
?>
Ingredients *
// retreiving the recipe groups
$ingredients = new Ingrident();
if(Input::exists()){
$data = $ingredients->findByGroup(Input::get('food-group'));
}else
$data = $ingredients->findByGroup(1);
foreach ($data->results() as $ingredient) {
// displaying the options
echo ''.$ingredient->ingrident_name.'';
}
?>
Ingredient not listed ?
Add New Ingredient
这是我的剧本
function ajaxfunction(parent)
{
$.ajax({
url: 'process.php?food-group=' + parent;
success: function(data) {
$("#ingredients").html(data);
}
});
}
这是我的process.php文件
mysql_connect('localhost', 'root','');
mysql_select_db("online_recipes");
$result = mysql_query("SELECT * FROM `ingrident` WHERE `food_group_id_fk` = " . mysql_real_escape_string($_GET['food-group']));
while(($data = mysql_fetch_array($result)) !== false)
echo '', $data['ingrident_name'],'';
我的进口清单