【发布时间】:2015-01-06 22:48:21
【问题描述】:
我对使用 AJAX 和使用 json_encode 传递数据非常陌生。我有这个“aht”按钮,点击它会向我的 show_aht.php 脚本发送一个 AJAX 请求,该脚本将运行一个查询。我想保存结果并将其显示到我的 map.php 中。
问题:
在我的 map.php 中,我有一个 while 循环,当单击显示其中的内容时,它会输出方形(桌面)DIV 和另一个 DIV(站)。 Here is the fiddle so you may understand。我希望 show_aht.php "TIME" 的结果显示在我的 WHILE LOOP 在 map.php 中生成的 DIV 中。
怎么可能做到这一点?我知道 AJAX 和 PHP 不能相互交互,这就是我需要帮助的原因。如果这不能完成,我还能如何在每个输出的 DIV 上显示从 show_aht.php 到其相应用户名的时间?我展示了大约 200 个。
提前致谢。
map.php(只显示while循环的最后一行,输出所有DIV)
//desk DIV
while(somequery){
....
echo '<div class="' . $class . '" data-rel="' . $id . '" style="left:' . $x_pos . 'px;top:' . $y_pos.'px;">' . $sta_num . '</div>' . "\n";
}//end while
//station DIV
while(some query){
.....
echo '<div class="station_info_" id="station_info_' . $id . '" style="left:' . $x_pos . 'px;top:' .$y_pos . 'px;"><p class="numb">User:' . $user .'<br>Station:' . $hostname . '<br>Pod:' . $sta_num . '<br>Section:' . $sec_name . '<br>State:' . $state .'<br></p></div>' . "\n";
}//end while
map.php(AJAX 部分)
<div id="aht"><!--aht button-->
<button id="aht_button">AHT</button>
</div><!--aht button-->
<script type="text/javascript">
$(document).ready(function() {
$('#aht').click(function(){
$.ajax({
type:"POST",
url : "show_aht.php",
data: , // pass data here
dataType: 'json',
success : function(data){
}//end success
});//end ajax
});//end click
});//end rdy
</script>
show_aht.php(显示循环和我希望返回数据的第一部分)
foreach($memo_data as $v){
foreach($user_data as $m){
if($v['memo_code'] == $m){
echo " User: " .$m. " Time: " . $v['avg_handle_time'] . "<br>";
}
elseif( $v['memo_code'] != $m){
echo "User: " . $m . " Time: N/A <br>";
}
}
}
【问题讨论】:
标签: javascript php jquery ajax mysqli