ajax和javascript drilldown脚本添加

时间:2015-05-28 01:10:31

标签: javascript php jquery ajax

我有一个make / model / engine搜索表单,用户选择make然后填充模型,用户选择模型并填充引擎。我遇到的问题是几个制造商(制造商)使用完全相同的模型。我只根据模型选择引擎。我想修改脚本,以便它根据make AND模型选择引擎,这将解决我的问题。我对javascript有点熟悉,但我不是专家,我在aircraftMakeModel.php文件中看到了ajax请求,但不知道如何将make添加到查询中。我已经包含了下面使用的三个文件。提前感谢任何帮助。

由于

汤姆

aircraftMakeModel.php

    <script type="text/javascript">
$(document).ready(function()
{
$('#aircraftMake').change(function()
{
var make=$(this).val();
var dataString = 'make='+ make;

$.ajax
({
type: "POST",
url: "include/getAirFrame.php",
data: dataString,
cache: false,
success: function(html)
{
$('#aircraftModel').html(html);
}
});

});

});





$(document).ready(function()
{
$('#aircraftModel').change(function()
{
var model=$(this).val();
var dataString = 'model='+ model;

$.ajax
({
type: "POST",
url: "include/getEngine.php",
data: dataString,
cache: false,
success: function(html)
{
$('#engineModel').html(html);
}
});

});

});
</script>

getAirFrame.php

    <?php 
include "../connection.php";
$q = $_POST['make'];
$q = addslashes($q);

$rs=mysqli_query($link,"SELECT DISTINCT(`aircraftModel`) FROM `aircraftData` WHERE `aircraftMake` = '$q' ORDER BY aircraftModel ; ");

echo '<option value="0">Aircraft Model</option>';
 while($data = mysqli_fetch_row($rs)){


$sa=$data[0];


echo '<option value="'.$sa.'">'.$sa.'</option>';

 ?>

<?php } ?>

getEngine.php

    <?php 
include "../connection.php";
$q = $_POST['model'];
$q = addslashes($q);


$rs=mysqli_query($link,"SELECT DISTINCT(`engineModel`) FROM `aircraftData` WHERE `aircraftModel` = '$q' ORDER BY engineModel");

echo '<option value="0">Engine Model</option>';
 while($data = mysqli_fetch_row($rs)){


$sa=$data[0];
echo '<option value="'.$sa.'">'.$sa.'</option>';

 ?>

<?php } ?>

1 个答案:

答案 0 :(得分:1)

如果你想在ajax调用上发送make和model来获得这样的引擎应该有效。调用以获取模型,然后将make添加到ajax请求数据以获取引擎。

注意:不确定这是否是拼写错误$('#marke')

$(document).ready(function(){
  
  $('#marke').change(function() {
    
    //make id
    var id=$(this).val();
    var dataString = 'id='+ id;

    $.ajax({
      type: "POST",
      url: "include/getph.php",
      data: dataString,
      cache: false,
      success: function(html) {
        $('#model').html(html);
      }
    });

  });
});



$(document).ready(function() {
  
  $('#model').change(function(){
    
    //make id
    var id = $('#marke option:selected').val();
    
    //model id
    var id1=$(this).val();
    
    var dataString = 'id1='+ id1 + '&id=' + id;

    $.ajax({
      type: "POST",
      url: "include/getph2.php",
      data: dataString,
      cache: false,
      success: function(html) {
        $('#engine').html(html);
      }
    });
  });
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>