[英]Bootstrap Modal appear only when there is an AJAX response
我想让Bootstrap Modal仅在AJAX响应时出现。 否则,我希望隐藏此Bootstrap 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
乘客登录:用户名ali密码12345678
此致Alixali
更改$("#myModal").modal();
到$("#myModal").modal("show");
并使用$(".myModals").modal("hide");
这是有关模态的Bootstrap API文档的链接
尝试success: function(response){ if(response != '') { $("#myModal").modal('show'); $("#modalbodyscreen").html(response); $.playSound('http://alixali.com/taxiapp/taxiappbeep');
success: function(response){ if(response != '') { $("#myModal").modal('show'); $("#modalbodyscreen").html(response); $.playSound('http://alixali.com/taxiapp/taxiappbeep');
}
}`
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.