Run another javascript when the user clicks “ok” in the notification

Basically I have a script that checks the database every 10 seconds and notifies the user if the data has been changed using the javascript warning window. But I need the database also to be changed when the user sees a warning and clicks "OK". So is it possible to run the javascript function when the user clicks “OK” on the javascript warning?

So for example

<html>
<head>
<script type="text/javascript">
function show_alert()
{
alert("New data!");
}
</script>
</head>
<body>

<input type="button" onclick="show_alert()" value="Show alert box" />

</body>
</html>

And when the user clicks OK, he should run this function

  function UpdateDB()
  {
      jQuery.ajax({
       type: "POST",
       url: "update.php",
       data: 'condition=ok',
       cache: false,

     });
 }
+5
source share
3 answers

alert . , , , , alert.

alert("New data!");
UpdateDB();
+8

, , - (). , , ( , !)...

...

if (confirm("Do you REALLY want this?")){
   //your AJAX CALL HERE
}
+8
function show_alert()
{
    alert("New data!");
    UpdateDB();
}
+6

All Articles