Guest User

Untitled

a guest
Sep 5th, 2018
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.67 KB | None | 0 0
  1. jQuery Ajax function does not complete call
  2. function register(){
  3. $.ajax({
  4. type: "POST",
  5. url: "user/registerConfirm.php",
  6. data: "regUsername=" + document.getElementById("regUsername").value +
  7. "&regPassword=" + document.getElementById("regPassword").value +
  8. "&myPassCheck=" + document.getElementById("myPassCheck").value +
  9. "&regEmail=" + document.getElementById("regEmail").value,
  10. dataType: "json",
  11. success: function(msg){
  12. alert("Success!");
  13. alert(msg);
  14. },
  15. complete: function(msg){
  16. alert("Displaying return value now.." + msg);
  17. },
  18. error: function(request, status, error) {
  19. //alert(request.responseText);
  20. alert("Error, returned: " + request);
  21. alert("Error, returned: " + status);
  22. alert("Error, returned: " + error);
  23. }
  24. });
  25. }
  26.  
  27. <?php
  28. session_start();
  29. ob_start();
  30.  
  31. require("../widgets/functions.php");
  32. connectToDB();
  33.  
  34. // Check email
  35. if (!filter_var(clean($_POST['regEmail']), FILTER_VALIDATE_EMAIL))
  36. {
  37. $error = 'Invalid email!';
  38. }
  39. else
  40. {
  41. if ( clean($_POST['regPassword']) == clean($_POST['myPassCheck']) && clean($_POST['regPassword']) != NULL
  42. && clean($_POST['regUsername']) != NULL && clean($_POST['regEmail']) != NULL ) // Register can be allowed
  43. {
  44. // Check if their already is a user with the same name..
  45. $sql="SELECT * FROM `users` WHERE username='".clean(trim($_POST['regUsername']))."'";
  46. $result=mysql_query($sql);
  47.  
  48. // Mysql_num_row is counting table row
  49. $count=mysql_num_rows($result);
  50.  
  51. if($count==1){
  52. // Their was already a user with this name!
  53. $error = 'Registration failed - username already taken..';
  54. }
  55. else if ( $count == 0 ){
  56. // Registration allowed, no user found with the same name
  57.  
  58. // Encrypt password
  59. $encryptPass = md5($_POST['regPassword']);
  60.  
  61. $subject = "Confirmation registration";
  62. $message = '
  63. <html>
  64. <head>
  65. <title>Registration at codexplained</title>
  66. </head>
  67. <body>
  68. <p>Hello '.clean($_POST['regUsername']).',</p>
  69.  
  70. <p>Thank you for registering at our website!
  71. </p>
  72.  
  73. <p>If you wish, you can now edit your profile, to change your display options and/or to upload your own profile image!<br />
  74. We hope to see you commenting on our articles soon!<br />
  75. If you wish to receive more information - Please contact us, or message any of our moderators.</p>
  76. <hr />
  77. <p>- Current moderators - <br />
  78. Ruud<br />
  79. Willem<br />
  80. Quint
  81. </p>
  82. <hr />
  83. </p>
  84. - Contact details - <br />
  85. Codexplained.tk<br />
  86. Codexplained@gmail.com
  87. </p>
  88. </body>
  89. </html>
  90. ';
  91. $from = "Codexplained@admin.com";
  92. $headers = 'From: Codexplained'."rn";
  93. $headers .= 'MIME-Version: 1.0' . "rn";
  94. $headers .= 'Content-type: text/html; charset=iso-8859-1' . "rn";
  95. $to = clean($_POST['regEmail']);
  96. if ( mail($to,$subject,$message,$headers) )
  97. {
  98. // Success
  99. }
  100. else
  101. {
  102. // Failed
  103. }
  104. // Insert data
  105. $query = "INSERT INTO `users`
  106. (
  107. `Id` ,`Username` ,`Password` ,`Rank`,`E-mail` ,`PostAmount`, `ProfileImage`, `Ip`, `LastIP`
  108. )
  109. VALUES ( NULL , '".clean(trim($_POST['regUsername']))."' , '".$encryptPass."' , 'member', '".clean($_POST['regEmail'])."' , '0', 'none', '".$_SERVER['REMOTE_ADDR']."','".$_SERVER['REMOTE_ADDR']."' )
  110. ";
  111. mysql_query($query)or die(mysql_error());
  112.  
  113. $error = 'Registration completed!';
  114. }
  115. }
  116. else
  117. {
  118. if ( clean($_POST['regPassword']) != clean($_POST['myPassCheck']) )
  119. {
  120. $error = 'Passwords do not match...';
  121. }
  122. else
  123. {
  124. $error = 'Registration failed - not enough data..';
  125. }
  126. }
  127. }
  128.  
  129. echo $error;
  130.  
  131. //mysql_close();
  132. //header("location:../index.php?page=register");?>
  133.  
  134. function register(){
  135. $.ajax({
  136. type: "POST",
  137. url: "user/registerConfirm.php",
  138. data: "regUsername=" + document.getElementById("regUsername").value +
  139. "&regPassword=" + document.getElementById("regPassword").value +
  140. "&myPassCheck=" + document.getElementById("myPassCheck").value +
  141. "&regEmail=" + document.getElementById("regEmail").value,
  142. dataType: "text", // <-------- There
  143. success: function(msg){
  144. alert("Success!");
  145. alert(msg);
  146. },
  147. complete: function(msg){
  148. alert("Displaying return value now.." + msg);
  149. },
  150. error: function(request, status, error) {
  151. //alert(request.responseText);
  152. alert("Error, returned: " + request);
  153. alert("Error, returned: " + status);
  154. alert("Error, returned: " + error);
  155. }
  156. });
  157. }
Add Comment
Please, Sign In to add comment