我有两个单独的 javascipt 文件和一个 php 文件,在第一个 create.js 上,我使用 post 将变量发送到 get.php 文件,然后我想将这些变量从 get.php 发送到 register.js,怎么能我在 register.js 中获取这些变量并将它们用于下一步?
这是第一个 js 文件中的代码:
var fs = $('#fname').val();
var ls = $('#lname').val();
var name = $('#adduser').val();
var pass = $('#addpass').val();
var cpass = $('#conpass').val();
if (document.forms['form2'].fname.value == "" || document.forms['form2'].lname.value == "" || document.forms['form2'].adduser.value == "" || document.forms['form2'].addpass.value == ""){
alert("Input the required Filled!");
}
else{
var vals;
var request = $.ajax({
url:"ifexist.php", type:"POST",
data:{
n:name
}
});
request.done(function(data){
vals = data; //alert(data);
if (vals == "1"){
alert("Username Already Exist!");
}
else
if(pass==cpass){
var request1 = $.ajax({
type: "POST",
url:"get.php",
data:{ fi:fs, la:ls, na:name, pa:pass}
});
request1.done(function(data){
alert("Not yet!");
location.href = 'captcha.html';
// setTimeout(function() {location.href = 'captcha.html';},1500);
});
}
else
alert("Password did not match!");
});
}
这是第二个js文件:
$.getJSON('get.php', function(data) {
// Inside your success callback:
var fir = $("#fi").html(data.uf);
var las = $("#la").html(data.ul);
var nam = ("#na").html(data.un);
var pas = $("#pa").html(data.up);
alert("Success!");
var request = $.ajax({
type: "POST",
url:"adduser.php",
data:{ f:fir, l:las, n:nam, p:pas}
});
request.done(function(data){
alert("Success!");
//setTimeout(function() {alert("Success!");},1500);
});
});
这是php文件:
<?php
$uf = $_POST['fi'];
$ul = $_POST['la'];
$un = $_POST['na'];
$up = $_POST['pa'];
//add to associative array
$result['fi'] = $uf;
$result['la'] = $ul;
$result['na'] = $un;
$result['pa'] = $up;
// encode as json and echo
echo json_encode($result);
?>