Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/373.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 如果数据库中已经存在用户,我想通过php get方法发送错误消息,但随后在不使用get变量的情况下重置url_Javascript_Php - Fatal编程技术网

Javascript 如果数据库中已经存在用户,我想通过php get方法发送错误消息,但随后在不使用get变量的情况下重置url

Javascript 如果数据库中已经存在用户,我想通过php get方法发送错误消息,但随后在不使用get变量的情况下重置url,javascript,php,Javascript,Php,通过url获取错误消息后,我将通过p标记抛出一条错误消息 然后使用window.location.pushstate({},“Hide”,“”)方法获得一个干净的url,而不显示错误消息 这是我的php代码 header('Location:../register.html?error=1'); 这是我的javascript代码 var currentUrl = $(location).attr('href'); if (currentUrl.match(/error=1/g))

通过url获取错误消息后,我将通过p标记抛出一条错误消息

然后使用window.location.pushstate({},“Hide”,“”)方法获得一个干净的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");

    }
var currentUrl=$(位置).attr('href');
if(currentUrl.match(/error=1/g)){
$('#erroru').html('用户已存在,请访问该页面');
$('#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");
}
窗口。位置。分配(“”);在mac系统上运行良好,错误显示在p标记中,url不包含get method错误变量,但在windows上不起作用

以及window.history.pushState({},“Hide”,和“”);适用于windows系统,错误显示在p标记中,url不包含get method错误变量,但不适用于mac 在这两个系统中,我都使用chrome,使用php会话

您可以将会话定义为会话_start()

然后,您可以通过会话发送错误消息


例如:$\u会话['error']=“您的错误消息”

为什么不直接使用Ajax呢?这样,您就不需要关心URL,并且可以返回所需的任何数据。如果您不想将错误消息作为URL的一部分,那么为什么要将浏览器重定向到那里?这没有什么意义。错误消息将替换在未发生错误时将被回复的内容。可以对该错误消息进行评估,然后由客户机自己决定下一步要做什么。