PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, October 27, 2022

[FIXED] Why ajax.stop works not only one time

 October 27, 2022     jquery     No comments   

Issue

I want, that a ajax.stop function works only for one time - at the first pageload, after that, I don't need this function. For that I have tried it with this code.

if(init===false)
      {     
            console.log('1) loadpage start');
            load_page(<?php echo $page->id;?>);
            //Wait till the page is recieved, than go on
            $(document).ajaxStop(function() {
                  console.log('2) load page -> ajaxStopp init:'+init);
                  setup_elements();
            });                       
            init=true;
      }      

I wondering why the ajaxstop function will work again if I do later another ajaxcall. At this I get the "2)" message from the console instead I see that the variable "Init" is true.

Maybe I understand the way which ajax.stop works wrong?


Solution

Register a handler to be called when all Ajax requests have completed. documentation

So what you wish to do probably is this:

$(document).ajaxStop(function() {
  if(init===false){
    console.log('2) load page -> ajaxStopp init:'+init);
    setup_elements();
    init=true;
  }
});

So you just misplaced your if condition.

Now ajaxStop() will still execute every time an ajax resquest has completed... But will do nothing, except on page load.



Answered By - Louys Patrice Bessette
Answer Checked By - Robin (PHPFixing Admin)
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing