gpt4 book ai didi

javascript - 尝试通过 AJAX 从多个窗口传递多个变量

转载 作者:行者123 更新时间:2023-12-03 08:28:38 26 4
gpt4 key购买 nike

我试图将多个变量从两个不同的窗口传递到同一个 PHP 脚本中。这可能吗?如果没有,最好的行动方案是什么?

谢谢

验证电子邮件.html

<script type = "text/javascript" src = "js/js_functions.js"> </script>  
<form method="post" onsubmit = "return testAjax();" />
<input type="email" placeholder="email" name="email" required maxlength = "50"><br>
<input type="email" placeholder="re-enter email"name="reemail" required maxlength = "50"><br>
<input type="submit" value="Verify Email">
</form>

<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

signup.html:

<script type = "text/javascript" src="js/js_functions.js"></script>
<form method="post" onsubmit="return ajaxTest();"/>
<input type="text" placeholder="username" name="username" required = "required" maxlength = "15"><br>
<input type="password" placeholder="password" name="password" required = "required" pattern = "(?=.*\d)(?=.*[A-Z]).{10,}"><br>
<input type="password" placeholder="re-enter password"name="repassword" required = "required"><br>
<p class = "passwordreq">Password must:</p>

<input type="submit" value="sign up"> <input type="button" value="go back" onclick="window.location='index.html'">
</form>
<script src='http://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.3/jquery.min.js'></script>

js_函数

var username, password;
function setUsrandPass(form)
{
if(form.password.value != form.repassword.value)
{
alert("Passwords do not match");

}

else {
username = form.username.value;
password = form.password.value;

window.location = 'verifyemail.html';

}

return false;
}

function ajaxTest()
{
if(form.email.value != form.reemail.value)
{
alert("Emails do not match");

}

else
$.ajax({
type: 'GET',
url: 'signup_script.php',
data: {usr: username, pass: password, em: form.email.value},
});

return false;
}

PHP 脚本:

<?php 

include 'profile_Functions.php';

$username = $_GET['usr'];
$password = $_GET['pass'];
$email = $_GET['em'];

echo "got here!";

createUser($username,$password,$email);
?>

最佳答案

对于来自不同页面的内容来说这是不可能的。他们需要向 PHP 脚本发出相同的请求来提供这两种数据。

您可以通过使用 PHP 写入某种数据存储(即文件或数据库)来规避此问题,然后等待其他脚本也写入,然后 PHP 可以进行所需的任何处理。

关于javascript - 尝试通过 AJAX 从多个窗口传递多个变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/33434942/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com