简体   繁体   中英

Show Alert message and redirect after click Ok

I am Using redirect function of Codeigniter with alert of JavaScript. I want to display message first before redirect to other page, but my code just directly redirect the page without displaying alert message. I need code in method of controller of codeigniter.I used code as follows in method of controller:

echo "<script type='text/javascript'>alert('Duplicate Users')</script>";
redirect('auth/login'),'location');

Plz Advice me Waiting for Response Thank You very Much for supporting me.

See this ..

Server code (PHP -> redirect) is fired up before Client Code (JS -> alert) . There are several solutions to this but the easiest one is to use one type of code for the functionality (either PHP or JS) ..

Let's use PHP to fire up JS for now, since that's what you're using ..

echo "<script>alert('Duplicate Users') ; window.location.href = 'auth/login'</script>"
<script>
  alert("Duplicate Users");
  window.location.href = "auth/login";
</script>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM