1
我做了一個測試jQuery ajax腳本,並在提交時將其附加到表單中,但儘管我的函數結尾處有return false
頁面在提交時保持刷新,我也沒有得到任何迴應。jQuery ajax不起作用
的形式是這樣的:
<form id="LogInForm" onsubmit="return LogIn();">
<input type="text" placeholder="Username" name="Username"><br/>
<input type="password" placeholder="Password" name="Password"><br/>
<input id="LogIn" type="submit" value="Sign In">
</form>
的腳本是這樣的:
function LogIn() {
$.ajax({
type:'POST',
url: 'login.php',
data:$('#LogInForm').serialize(),
success: function(response) {
alert(response);
}});
return false;
}
的login.php
文件只包含echo "test";
的index.php
和login.php
在同一個文件夾中。
非常感謝!這有點奇怪,因爲我的代碼與我在另一個項目中發佈的代碼幾乎相同(使用'onsubmit =「return function();」'thing),並且它工作正常。更具體地說,這一個:http://stackoverflow.com/questions/29460437/return-false-doesnt-work-for-jquery-post-form-submission-when-script-is-loade – Colin