There is no such function as jQuery.sleep(). When you added that line, it
caused a JavaScript error when tried to execute it, which stopped your
remaining code (the return false) from being executed.
 
Don't you have Firebug? Go get it right now and enable its Console and
Script tabs for your test page. You should see the error in the Firebug
console.
 
Is the real problem that you're expecting the result of your Ajax load()
call to be available immediately after making the call? It doesn't work that
way, and waiting one second isn't the right way to fix it. What if the
server is slow? And there's no such thing as a sleep or delay function in
JavaScript anyway. If you need to do something with the Ajax result, provide
a completion callback function as a second argument to .load(), and do the
rest of your processing in the callback.
 
http://docs.jquery.com/Ajax/load#urldatacallback
 
One last thing: any time you find yourself repeating a bit of code several
times like:
 
    $(this).parent().next().next()
 
don't do it! Instead, save that value once:
 
    var $target = $(this).parent().next().next();
 
and then use that in your subsequent code:
 
    $target.slideToggle('fast');
 
(The use of "$" in the variable name is a common convention around here, to
indicate that the variable is a jQuery object. It doesn't have any
significance other than that.)
 
-Mike



  _____  

From: Delifisek Tux

Hello,

I got noob question.

Following code used in one of my projects.
Ajax and other sliding things was working well.
The Problem is
Recently I use zebra colors. And now when I do ajax request, response shown
in opposite color.
to fix issue I add some even odd checker and it does not work as expected.
Later I found fix must be work after some time. so I put the 
jQuery.sleep(1000);

after adding this line following return false does not work..

Is there any advice ?

Thanks

        $('div.cResponseHotelVerifyCover').hide();
        $('.cResponseHotelPriceCheck').click(function() {
            var myId        = this.id;
            var idInd       = myId.replace('priceCheckId-','');
            var targetId    = '#responseHotelPrice-'+idInd;
            var sRequest    = this.href+'&av=true';
            var sHtmlVal    = this.innerHTML;

            $(this).parent().next().next().slideToggle('fast');
            $(this).parent().next().next().html('<img
src="<?=$this->plugin['loading_picture'];?>" alt="loading" title"loading" />
<?=evo::$lang[$this->lang]['_please_wait_your_request_verified_'];?>');
            $(this).parent().next().next().load(sRequest);

 
if($(this).parent().next().next().attr('class').split(' ').slice(-1) ==
'cOdd') {
                     $('div.cResponseAjaxTrue').addClass('cOdd');
                 } else {
                     $('div.cResponseAjaxTrue').addClass('cEven');
                 }
            $(targetId).html(sHtmlVal);
            return false;
        });
        $('div.cResponseHotelDetailCover:odd').addClass('cOdd');
        $('div.cResponseHotelVerifyCover:odd').addClass('cOdd');



Reply via email to