我有一个名为index.php的页面,在菜单中我必须根据城市选择城市我必须在auto suggetions中显示区域名称。我在下面存储下拉城市列表ID: 现在我的主题是我必须将jquery值传递给autocomplete.php页面
的index.php:
<select class="form-control" name="city" id="city">
<option value=''>Select city</option>
<?php while($row=mysql_fetch_array($result)) { ?>
<option value="value="<?php echo $row['CITY_ID']; ?>"><?echo $row['CITY_TITLE']?></option>
<?php } ?>
</select>
searchget.js(included in index.php):
$("#city").change(function() {
var city_id=$('#city').val();
alert(city_id);
$.ajax({
url: "autocompleteloc.php",
type: "POST",
data: { city_id1: city_id},
success: function (result) {
alert('success');
CallSearch();
}
});
});
autocomplete.php:
此页面包含区域代码:现在,我必须在此页面中传递jquery变量中的城市ID,
<?php
ini_set("display_errors",1);
include("config.php");
$q=$_POST['search'];
$cid=$_REQUEST['city1'];
$my_data=mysql_real_escape_string($q);
echo $sql="SELECT DISTINCT UNIT_AREA,CITY_ID FROM UNIT WHERE UNIT_AREA LIKE '%$my_data%' and CITY_ID='$cid'";
$result = mysql_query($sql) or die(mysql_error());
if($result)
{
while($row=mysql_fetch_array($result))
{
echo $row['UNIT_AREA']."\n";
}
}
?>
答案 0 :(得分:1)
您可以通过php
param
ajax
中的值
data: { CITY_ID1: CITY_ID},
所以,在php
中你可以获得价值
$_POST['CITY_ID1']
你应该用PHP学习ajax帖子。