我的代碼是在鉻,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>
嘗試'$(this).serializeArray();'而不是'new FormData(this)' –
@PradeepSingh如果他有一個輸入類型文件,會發生什麼? – madalinivascu
控制檯說什麼? – madalinivascu