gpt4 book ai didi

forms - Ajax POST 成功时的 Jquery 通知

转载 作者:行者123 更新时间:2023-12-01 04:57:12 24 4
gpt4 key购买 nike

我创建的一些 jQuery 通知存在问题,这些通知是在用户通过 AJAX 提交注册 HTML 表单后根据 PHP 文件中回显的信息触发的。错误通知有效,但无法成功发布到数据库。我知道应该显示成功通知,因为数据已验证并写入数据库并且 AJAX 发布成功。但是成功通知不起作用。这种技术性的原因可能是什么?

我进行了以下设置:

signup.html(页面中包含以下 ajax*):

function registerUser(formKey) {
$.ajax({
type:"POST",
url:"engine/new_user.php",
data: $("#"+formKey).serialize(),
cache:false,
success: function(data) {

if(data == -3){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#user-exists-notification").fadeIn(1000);
}
if(data == -4){
$("#account-created").fadeIn(1000);
}
if(data == -1){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#fields-complete-notification").delay(1000).fadeIn(1000);
}
if(data == -2){
$("html, body").animate({ scrollTop: 0 }, 600);
$("#pw-confirm-notification").delay(1000).fadeIn(1000);
}
},
error: function(data) {

}
});
}

new_user.php

 require("register-classes.php");

$register=new Register($_POST['fname'], $_POST['lname'], $_POST['email'], $_POST['sex'], $_POST['birthdate'], $_POST['phone'], $_POST['country'], $_POST['alias'], $_POST['handle'], $_POST["password"], $_POST["cpassword"], $_POST['network']);

if($register->checkFields()== false){

echo -1;

} else if($register->confirmPasswords()== false){

echo -2;
}else if($register->registerUser()!=false){


echo -4;
} else if($register->registerUser()==false){
echo -3;
}


and register-classes.php (which contains classes for processing sign up form)

class Register {

public function __construct($fname, $lname, $mail, $sex,
$birthday, $phonenumber, $regCountry, $alias, $username,
$password, $conf_password, $network_site) {

//Copy Constructor
$this->site=$network_site;
$this->firstname=$fname;
$this->lastname=$lname;
$this->email=$mail;
$this->sex=$sex;
$this->birthdate=$birthday;
$this->phone=$phonenumber;
$this->country=$regCountry;
$this->displayname=$alias;
$this->handle=$username;
$this->salt="a2cflux9e8g7ds6ggty589498j8jko007876j89j8j7";
$this->password=crypt($this->salt.$password);
$this->joindate=date("Y-m-d H:i:s");
$this->confirm_password1=$password;
$this->confirm_password2=$conf_password;

}

public function registerUser(){

$database=new Database();
$database->getConnection();
$database->startConnection();

//Check database to insure user and email address is not already in the system.
$checkUsers= mysql_query("SELECT network_users.network_id
FROM network_users, network_profile
WHERE network_users.handle = '$this->handle'
OR network_profile.email = '$this->email'");

$numRecords= mysql_num_rows($checkUsers);

if($numRecords == 0){

$addUser= mysql_query("INSERT INTO network_users(handle, password, date_created, parent_network, site_created, active, account_type, del)
values('$this->handle', '$this->password', '$this->joindate',' fenetwork', 'network', 'active', 'standard', 'F')") or die(mysql_error());

$networkId=mysql_insert_id();

$addProfile= mysql_query("INSERT INTO network_profile(network_id, first_name, last_name, email, sex, birthdate, phone, country, display_name, del)
values('$networkId', '$this->firstname', '$this->lastname', '$this->email','$this->sex', '$this->birthdate', '$this->phone', '$this->country', '$this->displayname', 'F')") or die(mysql_error());

$this->addUser;
$this->addProfile;

return true;

}
else{

return false;
}
}

public function checkFields(){
if(($this->firstname)!="" && ($this->lastname)!="" && ($this->email)!="" && ($this->sex)!="" &&
($this->birthdate)!="" &&($this->country)!="" && ($this->handle)!="" && ($this->password)!=""){

return true;
} else {

return false;
}

}

public function confirmPasswords(){

if($this->confirm_password1==$this->confirm_password2){

return true;
} else {

return false;
}
}

private $site, $firstname, $lastname, $email,
$sex, $birthdate, $phone, $country, $displayname,
$handle, $password, $salt, $joindate, $confirm_password1, $confirm_password2;

protected $addUser, $addProfile;

}

最佳答案

我发现了这个问题。该问题是由于 printf() 函数属于数据库类中的一些类成员造成的。他们在函数完成并返回 registerUser() 中的 bool 值 true 或 false 时造成中断;

感谢大家的帮助和帮助。我想放弃投票,但我没有足够的声望点。哈哈。

关于forms - Ajax POST 成功时的 Jquery 通知,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13620451/

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