sampa420 Posted April 1, 2011 Share Posted April 1, 2011 Hi developers, I develop a feature to recover the password for the user, but I'm having trouble to retrieving the value of json. I am pasting my code and if someone can help me. My engine JS $("#mailResetUsrPass").click(function () { $.ajax({ type: 'post', dataType: 'json', url: "user_confirmSend.php", data: { mailFromUser: resetMail }, beforeSend: function () { $("#mailResetUsrPass").removeClass("button_div"); $("#mailResetUsrPass").html("<img src='img/login/AJAX_loading.gif' width='17' height='17'/>").delay(1500); }, success: function (resJson) { if (resJson === false) { $("#mailResetUsrPass").html("<img src='img/login/iconOkMini.gif' width='17' height='17'/>").delay(); alert("Entrou certo"); $("#geral").fadeOut(); } else { alert("Entrou errado"); $("#mailResetUsrPass").html("<img src='img/login/icon_error.gif' width='17' height='17'/>").delay(200, function () { $('#email_fpass').val(""); alert("e-mail n\xE3o encontrado!"); $("#geral").fadeOut(); return false; }); } } }); } }); Send mail <?php ob_start(); // @Author: Alexandre Melo(CluBEE), alexandre.melo@clubee.com.br, alexmelo8813@gmail.com session_start(); error_reporting(E_ALL | E_STRICT); //setting zone date_default_timezone_set('America/Sao_Paulo'); //Including user framework include_once 'smart.user.php'; require("class.phpmailer.php"); //DB, iam here. SmartUser::connectDb(); //TODO: MOVE TO USER FRAMEWORK function destroyer($string){ $string = strip_tags($string); // Remove HTML $string = htmlspecialchars($string); // Convert characters $string = trim(rtrim(ltrim($string))); // Remove spaces $string = mysql_real_escape_string($string); // Prevent SQL Injection return $string; } function generatePassword($length=9, $strength=0) { $vowels = 'aeuy'; $consonants = 'bdghjmnpqrstvz'; if ($strength & 1) { $consonants .= 'BDGHJLMNPQRSTVWXZ'; } if ($strength & 2) { $vowels .= "AEUY"; } if ($strength & 4) { $consonants .= '23456789'; } if ($strength & { $consonants .= '@#$%'; } $password = ''; $alt = time() % 2; for ($i = 0; $i < $length; $i++) { if ($alt == 1) { $password .= $consonants[(rand() % strlen($consonants))]; $alt = 0; } else { $password .= $vowels[(rand() % strlen($vowels))]; $alt = 1; } } return $password; } $user_email = destroyer($_POST['mailFromUser']); $sql = "select COUNT(*),id,email from smartphpcal_settings where email = '$user_email'"; $sql_result = mysql_query($sql); $sql_fetch = mysql_fetch_array($sql_result); if((int)$sql_fetch['COUNT(*)'] == 1){ $pwd[0] = generatePassword(7,7); $pwd[1] = md5($pwd[0]); $id_user = $sql_fetch['id']; $user_email = $sql_fetch['email']; $sql = "UPDATE smartphpcal_settings SET password = '$pwd[1]' where id = $id_user"; $sql_result = mysql_query($sql); $mail = new PHPMailer(); //Mailfunction $mail->IsSMTP(); // set mailer to use SMTP $mail->Mailer = "smtp"; //Usando protocolo SMTP $mail->From = "test@clubee.com.br"; $mail->FromName = "TICME - Troca de Senha"; $mail->Host = "localhost"; //specify main and backup server $mail->AddAddress($user_email); $mail->WordWrap = 50; //set word wrap $mail->SMTPAuth = "true"; // 'true' para autenticação $mail->Username = "teste@clubee.com.br"; $mail->Password = "";//senha de SMTP $mail->Subject = "TIC ME - Solicitação de nova senha"; $mail->IsHTML(true); $body = "<body> <table width=100% border=0 cellpadding=0 cellspacing=0><tr><td height=50px colspan=3 bgcolor=#3B5998> </td></tr>"; $body .= " <tr><td width=1% rowspan=4 bgcolor=#3B5998> </td>"; $body .= "<td width=98% align=center style=border-bottom-width:1px;>"; $body .= "<img src=http://www.clubee.com.br/calendar/img/login/Logo.png width=240 height=65 /></td>"; $body .= "<td width=1% rowspan=4 bgcolor=#3B5998> </td></tr>"; $body .= "<tr><td style=border-top-width:1px; border-top-color:#999>Olá, " . $sql_fetch['email'] . "</td></tr>"; $body .= "<tr><td> </td></tr><tr><td>Foi solicitado uma nova senha para o seu usuário.<br><br>A sua nova senha é: ".$pwd[0]; $body .= "</td></tr>"; $body .= "<tr><td colspan=3 bgcolor=#3B5998> </td></tr>"; $mail->Body = $body; if(!$mail->Send()){ echo "Ocorreu erros ao enviar o e-mail"; json_encode(array('success' => false)); exit; //sai do script sem executar o codigo } echo "Email Enviado com sucesso"; json_encode(array('success' => true)); } ?> Quote Link to comment https://forums.phpfreaks.com/topic/232358-problem-to-return-json-value/ Share on other sites More sharing options...
sampa420 Posted April 1, 2011 Author Share Posted April 1, 2011 anyone can help me? Tks Quote Link to comment https://forums.phpfreaks.com/topic/232358-problem-to-return-json-value/#findComment-1195505 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.