这是我在php文件中的代码我从中回忆起刷新php再次nd再次工作正常但现在我有$ id我在执行一些查询时得到现在我想发送它refresh.php页面在哪里查询将被执行然后我得到结果返回
function repeatAjax(){
var arrPoints;
$.ajax({
url: 'refresh.php',
cache: false,
success: function(result) {
if(result){
var resultJson = $.parseJSON(result);
refresh_point(resultJson["latitude"],resultJson["longitude"]);
}
}
}); }
这是我的refresh.php页面
<?php
$hostname_localhost ="localhost";
$database_localhost ="map";
$username_localhost ="root";
$password_localhost ="";
$localhost = mysql_connect($hostname_localhost,$username_localhost,$password_localhost)
or
trigger_error(mysql_error(),E_USER_ERROR);
mysql_select_db($database_localhost, $localhost);
//i want $id here so i can use it instead of 6
$query_search1 = "SELECT lat ,lng FROM van WHERE id =6";
$query_exec2 = mysql_query($query_search1) or die(mysql_error());
$row = mysql_fetch_assoc($query_exec2);
$row1= $row['lat'];
$row2= $row['lng'];
$advert = array(
'latitude' => $row['lat'],
'longitude' => $row['lng'],
);
echo json_encode($advert);
?>
代码工作真棒如果我不想发送一些东西来刷新php如果我只是输入id 6我得到返回OK好但我想发布一些东西但是如何?
答案 0 :(得分:0)
function repeatAjax(){
var arrPoints;
var id = '6';
$.ajax({
url: 'refresh.php',
data: id,
cache: false,
success: function(result) {
if(result){
var resultJson = $.parseJSON(result);
refresh_point(resultJson["latitude"],resultJson["longitude"]);
}
}
});
}
In php file you can recive vairable like below
$id=$_POST['id'];