【发布时间】:2014-11-16 08:52:48
【问题描述】:
一开始,我在我的页面中尝试了ajaxStart和ajaxStop,它们都不起作用,代码:
<!DOCTYPE html>
<html>
<head>
<title></title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<script language="javascript" src="jquery-1.11.1.js"></script>
</head>
<body>
<form name="form" method="post" action="">
<input id = "name" type="text" name = "name" value="">
<div id = "check"></div>
</form>
<script language="javascript">
$("#name").blur(function() {
$("#name").ajaxStart(function() {
$("#check").html("loading...");
alert("loading...");
});
$("#name").ajaxStop(function() {
$("#check").html("OK...");
alert("OK...");
});
$.ajaxSetup({
url : "check.php",
type : "POST",
success : function(data) {
$("#check").html(data);
},
});
$.ajax({
url : "checkname.php",
type : "POST",
data : {name : $("#name").val()},
datatype : "text",
beforeSend : function() {
console.log("beforeSend");
},
success : function(data) {
$("#check").html(data);
console.log("success");
},
error : function() {
$("#check").html("error");
console.log("error");
},
complete : function() {
console.log("complete");
},
});
});
</script>
</body>
</html>
然后,我找到了一个答案stackoverflow.com/questions/4034252/jquery-ajaxstart-not-working
告诉我改用document,当我使用以下代码时,它可以工作
$(document).ajaxStart(function() {
$("#check").html("loading...");
alert("loading...");
});
另外,我尝试了另一种方法,使用 jQuery 1.7.2,它适用于 $("#name").ajaxStart()
我的问题是:
1、为什么在 jQuery 1.11.1 中 $("#name").ajaxStart() 不起作用,与 1.7.2 相比有什么变化?
2、有没有一些网站可以告诉我jQuery各个版本的区别,详细点会更好。
任何帮助将不胜感激,谢谢。
【问题讨论】:
标签: javascript jquery ajax