2015-11-11 91 views
0

我的代碼是在鉻,safari工作,但它不工作在Firefox。Jquery ajax不能在火狐工作

這裏是我的代碼

<script> 
$(document).ready(function() { 

    $("#loginform").on('submit',(function(e) { 

     e.preventDefault(); 

     $('#loading').html("Loading...."); 

     $.ajax({ 
      url: "login.php", 
      type: "POST",   
      data: new FormData(this), 
      contentType:false,  
      cache: false,    
      processData:false, 
      async:false,      
      success: function(data) 
      { 
       $('#loading').hide(); 
       $("#message").html(data); 
      } 
     }); 

     return false; 

    })); 

}); 
</script> 

誰能解決這個問題???我有一個相同的腳本在同一頁中只有url是不同的,但它的工作正常,但這個腳本不工作。我得到空數據。但在鉻,Safari瀏覽器工作正常。

我的HTML代碼:

除非你知道具體笏你doing.The問題是 async:false凍結瀏覽器,直到AJAX調用完成(或者錯誤或成功)
<form role="form" method="post" id="loginform" action=""> 
      <div class="form-group"> 
       <label for="username">Username</label> 
       <input type="text" class="form-control" id="username" name="username" placeholder="Enter Username" required> 
      </div> 
      <div class="form-group"> 
       <label for="password"> Password</label> 
       <input type="password" class="form-control" id="password" name="password" placeholder="Enter password"> 
      </div> 
      <div class="checkbox"> 
       <label><input type="checkbox" value="" name="user_rememberme" checked>Remember me</label> 
      </div> 
       <div id="loading"></div> 
       <div id="message"></div> 
       <button type="submit" name="login" class="btn btn-success pull-right">Login</button> 
      </form> 
+0

嘗試'$(this).serializeArray();'而不是'new FormData(this)' –

+0

@PradeepSingh如果他有一個輸入類型文件,會發生什麼? – madalinivascu

+0

控制檯說什麼? – madalinivascu

回答

3

從來沒有在Ajax調用使用async:false。其設置爲true或過將其刪除(默認爲true).Implement錯誤塊,並從服務器端如果檢查錯誤

success: function(data) 
{ 
$('#loading').hide();  
$("#message").html(data); 
},error:function(data){ 
    console.log(data) 
} 
+0

我試圖刪除異步:假,並沒有在console.No錯誤。但仍然沒有工作 – dileepindla

+0

創建一個小提琴 – coolguy

+1

嘗試螢火蟲和檢查ajax調用是否正確login.php,檢查狀態500/404錯誤 – coolguy

0

試試這個:

<script> 
$(document).ready(function() { 

    $("#loginform").on('submit',(function(e) { 
     dta = $(this).serialize(); 
     e.preventDefault(); 

     $('#loading').html("Loading...."); 

     $.ajax({ 
      url: "login.php", 
      type: "POST",   
      data:dta,         
      success: function(data) 
      { 
       $('#loading').hide(); 
       $("#message").html(data); 
      } 
     }); 

     return false; 

    })); 

}); 
</script> 
+0

不工作... @madalin ivascu – dileepindla

+0

你使用的是什麼版本的Firefox? – madalinivascu

+0

firefox 42.0 @ madalin ivascu – dileepindla