Menu
Forums
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Trending
What's new
New posts
New profile posts
Latest activity
Members
Current visitors
New profile posts
Search profile posts
Upgrades
Log in
Register
What's new
Search
Search
Search titles only
By:
All threads
Latest threads
New posts
Trending threads
New posts
Search forums
Menu
Log in
Register
Navigation
Install the app
Install
More options
Contact us
Close Menu
Forums
Software Development
Programming
Programming Q&A
JQuery - AJAX Return Value
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Reply to thread
Message
<blockquote data-quote="Berk" data-source="post: 417437" data-attributes="member: 63611"><p>Hey Guys, So I'm doing a register system and it uses AJAX. </p><p></p><p>So my JQuery code: </p><p>[CODE]</p><p>$('#btn-login').click(function() {</p><p> var name = $('#login-username').val(); </p><p> var password = $('#login-password').val(); </p><p> $.ajax({</p><p> url : 'system/js/login.php', </p><p> method: 'POST',</p><p> data: {</p><p> name: name,</p><p> password: password</p><p> },</p><p> beforeSend: function() {</p><p>new PNotify({</p><p> title: 'Processing...',</p><p> text: 'Logging you in...',</p><p> type: 'info'</p><p>});</p><p> },</p><p> success:function(result) {</p><p> if(result == 'done') {</p><p> new PNotify({</p><p> title : 'Success!', </p><p> text: 'Logged in! Redirecting in a moment...',</p><p> type:'success'</p><p> </p><p> });</p><p> </p><p>var delay = 2000; </p><p>setTimeout(function(){ window.location = 'index.php'; }, delay);</p><p> } </p><p> else if(result == 'invalid') {</p><p> new PNotify({</p><p> title: 'Invalid!',</p><p> text: 'Invalid creedentials... Try again!',</p><p> type:'error'</p><p> });</p><p> }</p><p> }</p><p> });</p><p> });</p><p> // register </p><p> $('#btn-signup').click(function(){</p><p> var reg_username = $('#reg_username').val(); </p><p> var reg_pass = $('#reg_pass').val();</p><p> var reg_r_pass = $('#reg_r_pass').val();</p><p> console.log(reg_username,reg_pass,reg_r_pass);</p><p> $.ajax({</p><p> url : 'system/js/register.php',</p><p> data:{</p><p> reg_username:reg_username,</p><p> reg_pass:reg_pass,</p><p> reg_r_pass:reg_r_pass</p><p> },</p><p> method: 'POST',</p><p> beforeSend:function() {</p><p> new PNotify({</p><p> title: 'Registering...',</p><p> text: 'Sending data to database...', </p><p> type: 'info'</p><p> });</p><p> },</p><p> success: function(result) {</p><p> console.log(result);</p><p> if(result == "done") {</p><p> console.error('hi');</p><p> new PNotify({</p><p> title: 'Registered!',</p><p> text: 'You are registered successfully. For security reasons, please log in with your creedentials..',</p><p> type: 'success'</p><p> }); </p><p> }</p><p> else if(result == 'password') {</p><p> new PNotify({</p><p> title: 'Your passwords are incorrect!',</p><p> text: 'Your passwords do not match... Check them carefully!',</p><p> type: 'error'</p><p> }); </p><p> }</p><p> else if(result == 'username') {</p><p> new PNotify({</p><p> title: 'Your username is incorrect!',</p><p> text: 'Your username is taken... Please choose another one! ',</p><p> type: 'error'</p><p> }); </p><p> }</p><p></p><p> }</p><p> });</p><p> });</p><p>[/CODE]</p><p></p><p></p><p>system/js/register.php: </p><p>[PHP]</p><p><?php </p><p>include('../config.php'); </p><p>$username = $_POST['reg_username']; </p><p>$password = md5($_POST['reg_pass']); </p><p>$r_password = md5($_POST['reg_r_pass']);</p><p></p><p>if($password !== $r_password) {</p><p> echo 'password';</p><p> exit;</p><p>}</p><p>$check_username = mysql_query("SELECT * FROM users WHERE username = '{$username}'"); </p><p></p><p>if(mysql_num_rows($check_username) > 0){</p><p> echo 'username'; </p><p> exit; </p><p>}</p><p>$query = mysql_query("INSERT INTO users(username,password,rank) VALUES('{$username}','{$password}','1')");</p><p>if($query == 1){</p><p> echo json_encode('done'); </p><p></p><p>}</p><p> ?></p><p></p><p>[/PHP] </p><p></p><p>So my problem here is, system/js/register.php returns 'done' but this part don't work : </p><p>[CODE]</p><p> if(result == "done") {</p><p> console.error('hi');</p><p> new PNotify({</p><p> title: 'Registered!',</p><p> text: 'You are registered successfully. For security reasons, please log in with your creedentials..',</p><p> type: 'success'</p><p> }); </p><p> }</p><p>[/CODE] </p><p></p><p>How may I solve that? Thanks.</p></blockquote><p></p>
[QUOTE="Berk, post: 417437, member: 63611"] Hey Guys, So I'm doing a register system and it uses AJAX. So my JQuery code: [CODE] $('#btn-login').click(function() { var name = $('#login-username').val(); var password = $('#login-password').val(); $.ajax({ url : 'system/js/login.php', method: 'POST', data: { name: name, password: password }, beforeSend: function() { new PNotify({ title: 'Processing...', text: 'Logging you in...', type: 'info' }); }, success:function(result) { if(result == 'done') { new PNotify({ title : 'Success!', text: 'Logged in! Redirecting in a moment...', type:'success' }); var delay = 2000; setTimeout(function(){ window.location = 'index.php'; }, delay); } else if(result == 'invalid') { new PNotify({ title: 'Invalid!', text: 'Invalid creedentials... Try again!', type:'error' }); } } }); }); // register $('#btn-signup').click(function(){ var reg_username = $('#reg_username').val(); var reg_pass = $('#reg_pass').val(); var reg_r_pass = $('#reg_r_pass').val(); console.log(reg_username,reg_pass,reg_r_pass); $.ajax({ url : 'system/js/register.php', data:{ reg_username:reg_username, reg_pass:reg_pass, reg_r_pass:reg_r_pass }, method: 'POST', beforeSend:function() { new PNotify({ title: 'Registering...', text: 'Sending data to database...', type: 'info' }); }, success: function(result) { console.log(result); if(result == "done") { console.error('hi'); new PNotify({ title: 'Registered!', text: 'You are registered successfully. For security reasons, please log in with your creedentials..', type: 'success' }); } else if(result == 'password') { new PNotify({ title: 'Your passwords are incorrect!', text: 'Your passwords do not match... Check them carefully!', type: 'error' }); } else if(result == 'username') { new PNotify({ title: 'Your username is incorrect!', text: 'Your username is taken... Please choose another one! ', type: 'error' }); } } }); }); [/CODE] system/js/register.php: [PHP] <?php include('../config.php'); $username = $_POST['reg_username']; $password = md5($_POST['reg_pass']); $r_password = md5($_POST['reg_r_pass']); if($password !== $r_password) { echo 'password'; exit; } $check_username = mysql_query("SELECT * FROM users WHERE username = '{$username}'"); if(mysql_num_rows($check_username) > 0){ echo 'username'; exit; } $query = mysql_query("INSERT INTO users(username,password,rank) VALUES('{$username}','{$password}','1')"); if($query == 1){ echo json_encode('done'); } ?> [/PHP] So my problem here is, system/js/register.php returns 'done' but this part don't work : [CODE] if(result == "done") { console.error('hi'); new PNotify({ title: 'Registered!', text: 'You are registered successfully. For security reasons, please log in with your creedentials..', type: 'success' }); } [/CODE] How may I solve that? Thanks. [/QUOTE]
Insert quotes…
Verification
Post reply
Forums
Software Development
Programming
Programming Q&A
JQuery - AJAX Return Value
Top