Rabesh Lal Shrestha
Rabesh Lal Shrestha

Reputation: 304

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.

Upvotes: 0

Views: 11540

Answers (2)

Amr Ayman
Amr Ayman

Reputation: 1159

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>"

Upvotes: 1

James Lalor
James Lalor

Reputation: 1246

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

Upvotes: 0

Related Questions