ajaxStart() "$ is not defined"
<script src="js/jquery/jquery-1.6.js" type="text/javascript"></script>
how can I setup ajaxStart??
I get "$.ajaxStart is not a function"
function Loader(){
this.loader = null;
this.cnstr = function(){
if(!this.loader){
this.loader = DOM.div(document.body);
with(this.loader){
cl开发者_JS百科assName = 'loader';
innerHTML = 'loader';
style.display = 'none';
}
elm_position_center(this.loader);
$(this.loader).fadeIn(1000);
}
};
this.dstr = function(){
if(this.loader){
DOM.rmv(this.loader);
}
};
}
var Loader = new Loader();
$.ajaxStart(function(){
Loader.cnstr();
});
$.ajaxStop(function(){
Loader.dstr();
});
EDIT:
$.ajaxStart is not a function
window.onload = function(){
$.ajaxStart(function(){
Loader.cnstr();
});
$.ajaxStop(function(){
Loader.dstr();
});
};
this works..
$(document).ajaxStart();
your jquery file is probably missing or you didn't load it correctly
You need to ensure that jQuery is loaded. Try adding this to your document:
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.6.0/jquery.min.js"></script>
Try this:
$("#loadingAnimation").bind({
ajaxStart: function(){ $(this).show(); },
ajaxStop: function() { $(this).hide(); }
});
Essentially binding your loadingAnimationElement to the globally fired ajaxStart and ajaxStop events. Only shows up when you intend it to.
When jQuery is not performing any Ajax requests and a new request is initiated, it fires an ajaxStart event. If other requests begin before this first one ends, those new requests do not cause a new ajaxStart event. The ajaxStop event is triggered when the last pending Ajax request is completed and jQuery is no longer performing any network activity.
//Thanks Kevin Brown for reminding me to explain the example.
Since jQuery 3.5.0 aliases like ajaxStart
are deprecated.
We’ve also put AJAX event aliases on the list, they can be replaced by
.on('ajaxStart', …)
and the like. jQuery Migrate will warn about these now-deprecated methods, but they’ll stick around until jQuery 4.0.
http://blog.jquery.com/2020/04/10/jquery-3-5-0-released/
精彩评论