2016-03-03 61 views
0

嗨,我有以下代码,但我无法访问我的request.php文件中的值。我怎样才能通过使用AJAX的选择框中传递两个值

$(document).ready(function(){ 
    $("select.location").change(function(){ 
     var Did = $("input[name='district']").val(); 
     var selectedLocation = $(".location option:selected").val(); 
     $.ajax({ 
      type: "GET", 
      url: "request.php", 
      data: {location : selectedLocation, Did:Did}, 
     }).done(function(data){ 
      $("#response").html(data); 
     }); 
    }); 
}); 

和我request.php呼吁这样

if(isset($_GET["location"])) 
{ 
    $i=0; 
    $bfrom = $_GET["location"]; 
    $did= $_GET["Did"]; 
$sql = "SELECT distinct stopname FROM `route` WHERE `rfrom` LIKE '$bfrom' and did=$did"; 
$result = $conn->query($sql); 
+0

使用json传递多个值 – guradio

回答

0

先关数据,以及最重要的,为了安全需要参数查询。见PHP: Prepared statements and stored procedures

其次,你LIKE参数需要被前面和后面% - 如“%$ bfrom%” - 这使“通配符”数据搜索MySQL Wildcards

最后,你需要回应的回应AJAX调用,为了让接收的javascript拿起它:)

相关问题