javascript - 如果用户已经存在于数据库中,我想通过 php get 方法发送错误消息,然后在没有 GET 变量的情况下重置 url
问题描述
通过 url 获取错误消息后,我通过 p 标签抛出错误消息
然后使用 window.location.pushstate({}, "Hide", " http://localhost/shravari/project1/register.html ") 方法获得一个干净的 url 而没有错误消息
这是我的 php 代码
header('Location:../register.html?error=1');
这是我的 JavaScript 代码
var currentUrl = $(location).attr('href');
if (currentUrl.match(/error=1/g)) {
$('#erroru').html('User already exists, please <a href="login.html">login</a> to access the page');
$('#erroru').css('color','red');
$('#erroru').css('text-algin','center');
// window.location.assign('http://localhost/shravari/project1/register.html');
window.history.pushState({}, "Hide", "http://localhost/shravari/project1/register.html");
}
window.location.assign(' http://localhost/shravari/project1/register.html '); 在 mac 系统上运行良好,错误显示在 p 标签中,并且 url 不包含 get 方法错误变量,但在 windows 上不起作用
和 window.history.pushState({}, "Hide", " http://localhost/shravari/project1/register.html "); 适用于windows系统,错误显示在p标签中,url不包含get方法错误变量,但在mac上不起作用并且在两个系统中我都使用了chrome
解决方案
使用 php 会话。
您可以将会话定义为 session_start();
然后您可以通过会话发送错误消息
例如:$_SESSION['error'] = "你的错误信息";
推荐阅读
- c# - 调用ajax post方法时发生内部服务器错误
- python - 字典循环的大 O
- java - Optional 使用 Mockito 返回空对象
- angular - Tippy.js 仅在 Angular 项目的第一页刷新后才有效
- python - 什么是相似性搜索的现代方法?
- c# - 带有 SQL 和 where 子句的 execute.scalar 始终返回 0
- asp.net - HTML5 输入日期类型
- database - 树的内部连接根到表
- pointers - 无法理解结构中的“typedef”和指针用法(C)
- powershell - Powershell 在 foreach 中没有得到 Item 异常