some JQuery scripts in web page runs twice. What is all about ? Maybe somebody faced such problem ?
For example(code that gets total items number from DB and runs in $(document).ready(function(){}); ):
$.post("/index/getitemscount/", {} ,function(data){
$('#items_count_div').html(data);
}, 'text');
开发者_运维技巧
As I see in FireBug(Firefox plugin), code runs twice...
Your help would be appreciated.
bounce - i've experienced this and it's usually boiled down to the fact that a partial $ajax request is populating a div with both html AND related jquery code. even tho' the html is overwritten each time, the jquery events are being attached multiple times. you'll either have to check for those events being bound and either rebind or unbind (http://api.jquery.com/unbind/) and bind or, place the jquery code in the parent page, rather than the partial.
of course, that may not be the case but certainly it's the same symptoms that I had experienced.
This snippet is too little to give you an answer. There could be several reasons within your page that may cause this. Use Firebug's Javascript debugger, look at the function that contains this snippet (if any), see where it's called from, etc. In other words: start debugging, because we can't do that without a complete page render.
精彩评论