2016-03-31 24 views
0

Web sitemde çalıştırdığım bu komut dosyası benim için bir şifre sıfırlama sistemi. i hata iletileri burada görünmüyor komut dosyası çalıştırdığınızda benim ajax komutAjax Yanıt İletileri Çalışmadı

burada

benim php komut burada

include '../global.php'; 
    if (isset($_POST['forLogin'])) { 
     if (empty($_POST["forLogin"])) { 
      echo "1"; 
     } else { 
      $login = $_POST["forLogin"]; 
      if (forgot($login, $dblink) == true) { 
       echo "3"; 
      } else { 
       $response = forgot($login, $dblink); 
       echo $response; 
      } 
     } 
    } else { 
     echo "1"; 
    } 

benim ajax komut dosyası İşte

$(document).ready(function() 
{ 
    $('#doforgot').click(function() 
    { 
     var login=$("#login").val(); 
     var dataString = 'forLogin='+login; 
     $.ajax({ 
      type: "POST", 
      url: "Application/Run/Other/Forgot.php", 
      data: dataString, 
      cache: false, 
      beforeSend: function(){ $("#doforgot").val('Connecting...'); }, 
      success: function(data){ 
       if (data === "3") 
       { 
        $("#doforgot").val('Reset your Account!'); 
        $("#formsg").html('<div class="alert alert-success-light-text fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><i class="fa fa-trophy"></i> <strong>Success!</strong> <a href="help/alerts" class="alert-link">We have just an email with a link to reset your password!</a>. Click on it and type a new password and hit change, then just login with your new password.</p><p><a href="help/report" class="btn btn-meadow">Report a glitch</a></p></div>'); 
       } 
       else if (data === "4") 
       { 
        $("#doforgot").val('Reset your Account!'); 
        $("#formsg").html('<div class="alert alert-hearts-light fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><strong>Forgot Failed</strong> · <a href="#" class="alert-link">The account does not exists</a>. Change a few things and try submitting again.</p><p><a href="help/report" class="btn btn-berry">Report a glitch</a></p></div>'); 
       } 
       else if (data === "1") 
       { 
        $("#doforgot").val('Reset your Account!'); 
        $("#formsg").html('<div class="alert alert-hearts-light fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><strong>Forgot Failed</strong> · <a href="#" class="alert-link">Please fill in all the required fields</a>. Change a few things and try submitting again.</p><p><a href="help/report" class="btn btn-berry">Report a glitch</a></p></div>'); 
       } 
       else 
       { 
        $("#doforgot").val('Reset your Account!'); 
       } 

      } 
     }); 
     return false; 
    }); 
}); 

olduğunu fonksiyonları olan

function checkIfUsernameExists($text, $link) { 
    if ($stmt = $link->prepare("SELECT * FROM users WHERE username = ? LIMIT 1")) { 
     $stmt->bind_param('s', $text); 
     $stmt->execute(); 
     $stmt->store_result(); 
     if ($stmt->num_rows == 1) { 
      return true; 
     } 
    } 
} 
function checkIfEmailExists($text, $link) { 
    if ($stmt = $link->prepare("SELECT * FROM users WHERE email = ? LIMIT 1")) { 
     $stmt->bind_param('s', $text); 
     $stmt->execute(); 
     $stmt->store_result(); 
     if ($stmt->num_rows == 1) { 
      return true; 
     } 
    } 
} 
function forgot($login, $dblink) { 
    if (checkIfUsernameExists($login) == true) { 
     if ($stmt = $dblink->prepare("SELECT id, username, email, password, name FROM users WHERE username = ? LIMIT 1")) { 
      $stmt->bind_param('s', $login); 
      $stmt->execute(); 
      $stmt->store_result(); 
      $stmt->bind_result($forUserID, $forUsername, $forEmail, $forPassword, $forName); 
      $stmt->fetch(); 
      if ($stmt->num_rows == 1) { 
       mailResetLink($forEmail, $forUsername, $forName); 
       return true; 
      } 
     } 
    } elseif (checkIfEmailExists($login) == true) { 
     if ($stmt = $dblink->prepare("SELECT id, username, email, password, name FROM users WHERE email = ? LIMIT 1")) { 
      $stmt->bind_param('s', $login); 
      $stmt->execute(); 
      $stmt->store_result(); 
      $stmt->bind_result($forUserID, $forUsername, $forEmail, $forPassword, $forName); 
      $stmt->fetch(); 
      if ($stmt->num_rows == 1) { 
       mailResetLink($forEmail, $forUsername, $forName); 
       return true; 
      } 
     } 
    } else { 
     echo "4"; 
    } 
} 

Ve sonunda işte benim html betiğim

<!DOCTYPE html> 
<html> 
<head> 
    <title>Ajax Test</title> 

</head> 
<body> 
<form action="" method="post"> 
Username or Email 
<input type="text" class="input" id="login"> 
<input type="submit" class="button button-primary" value="Reset your Account!" id="doforgot"> 
<div id="formsg"></div> 
</div> 
</form> 

</body> 
</html> 

Bazı nedenlerle sayfayı yeniden yükler ve yapmamalı.

cevap

0

Kodunuzu denedim ve birkaç ayardan sonra iyi çalışıyor. Bu senin html ve javascript mi?

Çalışan bir php sunucunuz var mı? ajax çağrınızdaki URL'niz bir url'ye olmalıdır

Sadece javascript'i html dosyasına birleştirdim. çünkü tembelim, indeks dosyasını php ile aynı dizine koy. Php sunucunuzun çalıştığından emin olun.

index.html

<!DOCTYPE html> 
<html> 
<head> 
    <title>Ajax Test</title> 
    <script src="https://code.jquery.com/jquery-2.2.2.min.js" integrity="sha256-36cp2Co+/62rEAAYHLmRCPIych47CvdM+uTBJwSzWjI=" crossorigin="anonymous"></script> 
    <script> 
     $(document).ready(function() 
      { 
       alert('asdf'); 

       $('#doforgot').click(function() 
       { 
        var login=$("#login").val(); 
        var dataString = 'forLogin='+login; 
        $.ajax({ 
         type: "POST", 
         url: "inv.php", 
         data: dataString, 
         cache: false, 
         beforeSend: function(){ $("#doforgot").val('Connecting...'); }, 
         success: function(data){ 
          if (data === "3") 
          { 
           $("#doforgot").val('Reset your Account!'); 
           $("#formsg").html('<div class="alert alert-success-light-text fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><i class="fa fa-trophy"></i> <strong>Success!</strong> <a href="help/alerts" class="alert-link">We have just an email with a link to reset your password!</a>. Click on it and type a new password and hit change, then just login with your new password.</p><p><a href="help/report" class="btn btn-meadow">Report a glitch</a></p></div>'); 
          } 
          else if (data === "4") 
          { 
           $("#doforgot").val('Reset your Account!'); 
           $("#formsg").html('<div class="alert alert-hearts-light fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><strong>Forgot Failed</strong> · <a href="#" class="alert-link">The account does not exists</a>. Change a few things and try submitting again.</p><p><a href="help/report" class="btn btn-berry">Report a glitch</a></p></div>'); 
          } 
          else if (data === "1") 
          { 
           $("#doforgot").val('Reset your Account!'); 
           $("#formsg").html('<div class="alert alert-hearts-light fade in"><button type="button" class="close" data-dismiss="alert" aria-hidden="true"><i class="fa fa-times"></i></button><p><strong>Forgot Failed</strong> · <a href="#" class="alert-link">Please fill in all the required fields</a>. Change a few things and try submitting again.</p><p><a href="help/report" class="btn btn-berry">Report a glitch</a></p></div>'); 
          } 
          else 
          { 
           $("#doforgot").val('Reset your Account!'); 
          } 

         } 
        }); 
        return false; 
       }); 
      }); 
    </script> 
</head> 
<body> 
<form action="" method="post"> 
Username or Email 
<input type="text" class="input" id="login"> 
<input type="submit" class="button button-primary" value="Reset your Account!" id="doforgot"> 
<div id="formsg"></div> 
</div> 
</form> 

</body> 
</html> 
+0

hol bir kodda bir fark görüyorsun, jquery dahil. Ben değil –

+0

neden benim .js jquery kullanır –

+0

evet var php çalışan –