1

我在 wordpress 网站上创建了一个登录表单,该表单将允许用户访问仅限会员的内容。我有三个功能login() resetPassword()register().

在我添加了第三个函数之前,login()和表单都可以正常工作,然后根本不会提交任何表单。resetPassword()register()

如果我删除该register()功能,那么其​​他表单将再次开始工作。此外,如果我将其他功能放在他们自己的<script>标签中,那么它们会按预期工作,但该register()功能仍然无法正常工作。

我一遍又一遍地查看代码,并尝试将其放置在不同的区域......我不确定是什么导致了问题。以前有没有人发生过这种情况?我如何解决它?

<script type="text/javascript">
function login()
{
    var email = document.getElementById("LoginUName").value;
    var pword = document.getElementById("LoginPWord").value;
    var xmlhttp;
    if (window.XMLHttpRequest)xmlhttp=new XMLHttpRequest(); 
    else xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
    xmlhttp.onreadystatechange=function(){document.getElementById('LoginScreen').innerHTML=xmlhttp.responseText;}
    xmlhttp.open('GET','login.php?EMail='+email+'&PWord='+pword,true);
    xmlhttp.send();
}
function resetPassword()
{
    var email = document.getElementById("ResetEMail").value;
    var xmlhttp;
    if (window.XMLHttpRequest)xmlhttp=new XMLHttpRequest(); 
    else xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
    xmlhttp.onreadystatechange=function(){document.getElementById('LoginScreen').innerHTML=xmlhttp.responseText;}
    xmlhttp.open('GET','passwordReset.php?EMail='+email,true);
    xmlhttp.send();
}
function register()
{
    var firstname = document.getElementById("RegisterFirstName").value;
    var lastname = document.getElementById("RegisterLastName").value;
    var email = document.getElementById("RegisterEMail").value;
    var pword = document.getElementById("RegisterPWord").value;
    var xmlhttp;
    if (window.XMLHttpRequest)xmlhttp=new XMLHttpRequest(); 
    else xmlhttp=new ActiveXObject('Microsoft.XMLHTTP');
    xmlhttp.onreadystatechange=function(){document.getElementById('LoginScreen').innerHTML=xmlhttp.responseText;}
    xmlhttp.open('GET','register.php?FirstName='+firstname+'&LastName='+lastname+'&EMail='+email'&PWord='+pword,true);
    xmlhttp.send();
}
</script>


<div id="LoginScreen">
<h1>Welcome to ****.</h1><br>
<h2>Please login or register below:</h2><br>
<form action="javascript: login()" method="get">
    <ul>
        <li>
            <h3>Username:&nbsp;</h3><input type="email" id="LoginUName" name="LoginUName" placeholder="Email address" />
        </li>
        <li>
            <h3>Password:&nbsp;</h3><input type="password" id="LoginPWord" name="LoginPWord" placeholder="Password"/>
        </li>
    </ul>
    <input type="submit" value="Login"/>
</form>
<br><hr><br>
<form action="javascript: resetPassword()" method="get">
    <h2>Forgot your password?</h2><br>
    Email address:&nbsp;<input type="email" id="ResetEMail" name="ResetEMail" placeholder="Email address" />&nbsp;&nbsp;<input type="submit" value="Reset" />
</form>
<br><hr><br>
<form action="javascript: register()" method="get">
    <h2>Register new user:</h2><br>
    <ul>
        <li>
            <h3>First Name:&nbsp;</h3><input type="text" id="RegisterFirstName" name="RegisterFirstName" placeholder="First Name" />
        </li>
        <li>
            <h3>Last Name:&nbsp;</h3><input type="text" id="RegisterLastName" name="RegisterLastName" placeholder="Last Name" />
        </li>
        <li>
            <h3>Email:&nbsp;</h3><input type="email" id="RegisterEMail" name="RegisterEMail" placeholder="email address" />
        </li>
        <li>
            <h3>Password:&nbsp;</h3><input type="password" id="RegisterPWord" name="RegisterPWord" placeholder="Password" />
        </li>
    </ul>
    <input type="submit" value="Register"/>
</form>

4

1 回答 1

2

这只是一个语法错误。你错过了一个+标志。

你有:

    xmlhttp.open('GET','register.php?FirstName='+firstname+'&LastName='+lastname+'&EMail='+email'&PWord='+pword,true);

它需要在+之后有一个标志email

xmlhttp.open('GET','register.php?FirstName='+firstname+'&LastName='+lastname+'&EMail='+email+'&PWord='+pword,true);

这就是为什么如果你把它放在两个单独的脚本中它会起作用的原因。一个语法错误导致整个脚本无效。

于 2013-01-07T23:02:19.883 回答