2016-07-02 71 views
0

我有以下形式.submit()不開火形式

<form action="" method="post" name="loginForm" id="loginForm"> 
    <div id="spinnerInsert"> 
     <div class="form-content"><input type="text" name="loginUser" id="loginUser" class="validate[required,minSize[3]]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginUser">Username</label><span class="form_hint">Enter your username here</span></div> 
     <div class="form-content"><input type="password" name="loginPassword" id="loginPassword" class="validate[required]" required /><span class="form_highlight"></span><span class="form_bar"></span><label for="loginPassword">Password</label><span class="form_hint">Enter your password here</span></div> 
    </div> 
    <div class="form-content buttons"><p><input name="action-login" type="submit" id="action-login" value="Sign In" class="button confirm" style="width: 140px;" /><br/><a href="">Register</a> &middot; <a href="">Forgot Password</a></p></div> 
</form> 

,然後在腳本

$('form#loginForm').submit(function(event) { 
    // Get data and submit 
    $('#spinnerInsert').spin(); 
    $.getJSON("lib/class/class.login.php", {loginUser: $('input#loginUser').val(), loginPassword: $('input#loginPassword').val(), queryType: "1"}) 
    .done(function(response) { 
     $('#spinnerInsert').spin(false); 
     if(response.success===0){ 
      // Show Error 
      toastr.error(response.message, 'Error'); 
      // If totalFails > 4, lock account and offer to reset password or email admin 
      if(response.totalFails>4) { 
       $('article#pageForm').html('<p id="accountLocked">Sorry, your account has been locked. Please <a href="">reset your password</a> or <a href="mailto:adminemail">contact the site admin</a> to unlock your account</p><p><a href="javascript:backToLogin();">Back to Sign In</a></p>'); 
      } 
     } else { 
      // Load Authentication Section 
      $('article#pageForm').html(response.data); 
     } 
    }); 
    event.preventDefault(); 
    return false; 
}); 

但由於某些原因,我每次按一次下面的代碼提交它只是重新加載這一頁。它根本不會觸發我的腳本。

它昨天工作,但不是今天,我不記得改變任何事情。我也試過$(document).on('submit','form#loginForm',function(event) {

http://spendit.dpdesignz.co/

+0

打開瀏覽器的錯誤控制檯,勾選「保存登錄」複選框,並期待在錯誤消息('$(...)。自旋不是一個function') – JJJ

回答

1

問題完整的示例是.spin()沒有定義。嘗試刪除包含.spin()的行,然後嘗試提交表單。

$('form#loginForm').submit(function(event) { 
    // Get data and submit 
    $.getJSON("lib/class/class.login.php", {loginUser: $('input#loginUser').val(), loginPassword: $('input#loginPassword').val(), queryType: "1"}) 
    .done(function(response) { 
     if(response.success===0){ 
      // Show Error 
      toastr.error(response.message, 'Error'); 
      // If totalFails > 4, lock account and offer to reset password or email admin 
      if(response.totalFails>4) { 
       $('article#pageForm').html('<p id="accountLocked">Sorry, your account has been locked. Please <a href="">reset your password</a> or <a href="mailto:adminemail">contact the site admin</a> to unlock your account</p><p><a href="javascript:backToLogin();">Back to Sign In</a></p>'); 
      } 
     } else { 
      // Load Authentication Section 
      $('article#pageForm').html(response.data); 
     } 
    }); 
    event.preventDefault(); 
    return false; 
}); 
+0

感謝。不知道爲什麼旋轉沒有被定義。它在'<! - Add Spin.js - > '。它正在工作。 :/ – dpDesignz

+0

可能的原因可能是因爲它在提交操作之後加載。 –

+0

原來我意外刪除了我標題中的另一個參考。別擔心。謝謝 :) – dpDesignz