javascript 单击确定后显示警报消息和重定向

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/25787265/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-28 05:01:11  来源:igfitidea点击:

Show Alert message and redirect after click Ok

javascriptphpcodeigniterredirectalert

提问by Rabesh Lal Shrestha

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:

我正在使用带有 JavaScript 警报的 Codeigniter 的重定向功能。我想在重定向到其他页面之前先显示消息,但我的代码只是直接重定向页面而不显示警报消息。我需要codeigniter控制器方法中的代码。我在控制器方法中使用了如下代码:

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.

Plz Advice me Waiting for Response 非常感谢您对我的支持。

回答by Amr Ayman

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) ..

服务器代码(PHP -> redirect)在客户端代码之前启动(JS -> alert)。有几种解决方案,但最简单的一种是使用一种类型的代码来实现功能(PHP 或 JS)。

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

现在让我们使用 PHP 来启动 JS,因为这就是您正在使用的 ..

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

回答by James Lalor

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