Javascript .done 不是一个函数
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/10416879/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
.done is not a function
提问by Niels
I've another problem. I get an error in FireFox and I don't know what my fault is. I always did it like this way and I never got an error. I already check lower/uppercase mistakes but I can't find anything.
我还有一个问题。我在 FireFox 中遇到错误,但我不知道我的错是什么。我总是这样做,我从来没有出错。我已经检查了小写/大写错误,但我找不到任何东西。
Thanks
谢谢
$.ajax({type: "POST", url: "ajax/check_username.php", data: {username: username}}).done is not a function
$.ajax({type: "POST", url: "ajax/check_username.php", data: {username: username}}).done 不是函数
<script type="text/javascript">
$(document).ready(function(){
$("#username").keyup(function(){
var username = $("#username").val();
$(".usernameFeedback").fadeIn("fast");
$.ajax({
type: "POST",
url: "ajax/check_username.php",
data: { username: username }
}).done(function( msg ) {
$("#loadingImage").hide();
if(msg.status != "error")
{
if(msg.available == "yes")
{
$(".usernameFeedback span").text(msg.message);
$(".usernameFeedback span").removeClass("notok");
$(".usernameFeedback span").addClass("ok");
}
else
{
$(".usernameFeedback span").text(msg.message);
$(".usernameFeedback span").addClass("notok");
}
}
});
return(false);
})
});
</script>
回答by ThiefMaster
Probably your jQuery version is too old. You need at least jQuery 1.5 for jqXHR objects to implement the Promiseinterface you are using.
可能你的 jQuery 版本太旧了。对于 jqXHR 对象,您至少需要 jQuery 1.5 才能实现您正在使用的Promise接口。
If you cannot upgrade for some reason, simply use the success
option:
如果由于某种原因无法升级,只需使用以下success
选项:
$.ajax({
type: "POST",
url: "ajax/check_username.php",
data: { username: username },
success: function(msg) {
}
});