'redirecting without the alertbox [duplicate]
My PHP code is redirecting to the provided page without showing the alert box even though I have provided it in the code. Here is the code :
echo "<script type='text/javascript'>alert('Registered Successfully.')</script>";
header("Location:/magz/index - Copy.php");
Solution 1:[1]
the php gets executed before it hits the browser. the JavaScript is executed after the PHP. In this case since PHP is redirecting the page, the JavaScript is never executed.
Solution
if($result == 1)
{
echo "<script type='text/javascript'>alert('Registered Successfully.');
window.location.assign(\"/magz/index - Copy.php\");</script>";
}
In this case, you are making JavaScript handle the redirect.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Josh S. |
