【发布时间】:2016-05-09 02:09:16
【问题描述】:
我想让我的引导模式仅在有 AJAX 响应时出现。否则,我希望隐藏此引导模式。
我已经完成了以下操作。但是,它不能正常工作。即使没有响应,Modal 也会一直显示。
JavaScript:
<script>
//$(dialog).close();
$(".dialog").parent().hide();
// execute alerts ajax function every 1 second
setInterval(alerts, 10000);
function alerts(){// define alerts function
$.ajax({ //create an ajax request to alerts.php
type: "GET",
url: "alerts.php",
dataType: "html", //expect html to be returned
success: function(response){
$("#myModal").modal();
$("#modalbodyscreen").html(response);
$.playSound('http://alixali.com/taxiapp/taxiappbeep');
}
});
}
// close and delete modals every 10 seconds
setTimeout(function(){
//$(dialog).close();
$(".dialog").parent().hide();
}, 10000);
</script>
alerts.php
<pre>
ini_set('display_errors', 'On');
session_start();
$driver_id = $_SESSION['userId'];
include "header.php";
$result = mysql_query("SELECT * FROM alerts WHERE driver_id = '$driver_id'");
$num = mysql_num_rows($result);
if ($num != 0) {
while($data = mysql_fetch_row($result))
{
echo "<h5>Contact No:</h5><br>";
echo $data[1]."<br>";
echo "<h5>Address:</h5><br>";
echo "https://www.google.com/maps/preview/@".$data[3].",".$data[2].",16z"."<br>";
echo "<h5>Distance (km):</h5><br>";
echo $data[5];
$_SESSION['distance'] = $data[5];
}
$delete_result = mysql_query("DELETE FROM alerts WHERE driver_id = '$driver_id'");
}
</pre>
请尽快给我建议/解决方案。
您可以在以下位置看到此应用: http://www.alixali.com/taxiapp/
驱动程序登录: 用户名 1111 密码1111
乘客登录: 用户名阿里 密码12345678
问候, 阿利克斯利
【问题讨论】:
-
我猜
header.php正在产生输出,然后是 ajax 成功回调中的response -
你尝试改变 $("#myModal").modal();到 $("#myModal").show();
标签: javascript php jquery ajax bootstrap-modal