11

.guys I have the following code:

echo ("<SCRIPT LANGUAGE='JavaScript'>
        window.alert('Succesfully Updated')
        </SCRIPT>");

what i want to do is that when i click ok on the windows.alert the page will be redirected to a my edit.php.

or how is it possible to create a javascript which will execute an insert query.

zerey
  • 871
  • 11
  • 19
  • 37
  • Jquery has built it means for calling server side code directly. You probably want to look at this previous question as a starting point http://stackoverflow.com/questions/861784/how-to-call-a-web-service-from-jquery. Also if you are interested in blocking the client side during your insert you can take a look at the jquery plugin blockui http://jquery.malsup.com/block/. – bwmfsu Mar 26 '11 at 16:26
  • @bwmfsu Sheez. When you have a platinum hammer, you really make all problems look like nails? jQuery is massive overkill here. – mplungjan Mar 26 '11 at 16:43
  • @mplungjan I misunderstood the question. I thought the question was about hitting an insert asynchronously maybe reading too much into this excerpt from the question _javascript which will execute an insert query_ I have been doing a lot of this within the last few weeks so that's where my mind is. – bwmfsu Mar 26 '11 at 17:39

4 Answers4

37

Alert will block the program flow so you can just write the following.

echo ("<script LANGUAGE='JavaScript'>
    window.alert('Succesfully Updated');
    window.location.href='http://someplace.com';
    </script>");
jasinth premkumar
  • 1,430
  • 1
  • 12
  • 22
Pickels
  • 33,902
  • 26
  • 118
  • 178
  • 2
    That way is not recommended, you don't send the header so you better write `exit;` after `echo` – miqbal Nov 30 '13 at 22:13
3

If you would like to redirect the user after the alert, do this:

echo ("<script LANGUAGE='JavaScript'>
          window.alert('Succesfully Updated');
          window.location.href='<URL to redirect to>';
       </script>");
Malte Hartwig
  • 4,477
  • 2
  • 14
  • 30
Imi Borbas
  • 3,683
  • 1
  • 19
  • 16
3

You could do this:

echo "<script>alert('Successfully Updated'); window.location = './edit.php';</script>";
Karl Nicoll
  • 16,090
  • 3
  • 51
  • 65
1

Use this if you also want to consider non-javascript users:

echo ("<SCRIPT LANGUAGE='JavaScript'>
           window.alert('Succesfully Updated')
           window.location.href='http://someplace.com';
       </SCRIPT>
       <NOSCRIPT>
           <a href='http://someplace.com'>Successfully Updated. Click here if you are not redirected.</a>
       </NOSCRIPT>");
jpakes
  • 33
  • 1
  • 4