When I am using JS with PHP i meet a problem
echo '<script type="text/javascript">alert("my alert");</script>';
header('Location: /toto.com/');
The JS alert isn't working
Thank you for your help
When I am using JS with PHP i meet a problem
echo '<script type="text/javascript">alert("my alert");</script>';
header('Location: /toto.com/');
The JS alert isn't working
Thank you for your help
Javascript is client side language and PHP is server side language so it is executed before your client side code will get executed. Now you are doing like this:
echo '<script type="text/javascript">alert("my alert");</script>';
header('Location: /toto.com/');
Fault
Your PHP script is putting HTML block first and then redirecting it to the location you have mentioned in your header() without giving any chance to your script to be executed.
Code should be like this
echo '<script type="text/javascript">alert("my alert"); window.location.href="/toto.com/";</script>';
This should work...
Try this.
echo ("<SCRIPT LANGUAGE='JavaScript'>
window.alert('Succesfully Updated')
window.location.href='http://localhost/test1.php';
</SCRIPT>");
Hope this will work for you..
headers already sent warning