2

My question : Can an infinite loop of ajax call can create problem ?

Given there is a code like :

 ajaxcall();
 function ajaxcall(){

    jQuery.ajax({
        type: "POST",
        url: myurl,
        data: mydata,
        cache: false,
        success: function(data){
            if (something )
            {
                 ajaxcall();
            }
        },
        error: function(){},
        complete: function(){}
    });
 }

As you can see, in executing the ajaxcall, if the something is true, it will execute again the ajaxcall().

In case where, the something condition is everytime true, can it cause some problems in navigator or server or something else ? And in case of 'yes there will be big problem', what are the ways to protect against this ?

Thanks for your attention...

UPDATE AFTER ANSWER

I ask this because in inspecting my WordPress Login page, i was wondering was will happened :

If someone with bad intention, open a navigator inspector to find the name of inputs inside form to generate data [in this case 'log' and 'pwd'], and use this kind of code to find a login [, and after a password] with use of navigator's console.

In making a condition on the returned data.

 sendCheckFormAnswer();
 function sendCheckFormAnswer(){

    jQuery.ajax({
        type: "POST",
        url: myLoginPostUrl,
        data: {log:generatedLogin,pwd:generatedPassword},
        cache: false,
        success: function(data){
            if (data.indexOf(badLoginMessage)>=0)
            {
                 codeTogenerateANewLogin();
                 sendCheckFormAnswer();
            } else {
                 alert(generatedLogin);
            }
        },
        error: function(){},
        complete: function(){}
    });
 }

In Addition , here is my login form page :

<form name="loginform" id="loginform" action="http://www.###########.fr/wp-login.php" method="post">
    <p>
        <label for="user_login">Identifiant<br>
        <input type="text" name="log" id="user_login" class="input" value="" size="20"></label>
    </p>
    <p>
        <label for="user_pass">Mot de passe<br>
        <input type="password" name="pwd" id="user_pass" class="input" value="" size="20"></label>
    </p>
    <p class="forgetmenot"><label for="rememberme"><input name="rememberme" type="checkbox" id="rememberme" value="forever"> Se souvenir de moi</label></p>
    <p class="submit">
        <input type="submit" name="wp-submit" id="wp-submit" class="button button-primary button-large" value="Se connecter">
        <input type="hidden" name="redirect_to" value="http://www.saint-pierre-de-curtille.fr/wp-admin/">
        <input type="hidden" name="testcookie" value="1">
    </p>
</form>

A bad login and bad password return bad login message. A good login and bad password return a bad password message.

1
  • Basically if you need to do this, then you're doing something wrong. It would be better to tell us exactly what you're trying to do so we can guide you in the right direction, rather than simply ask if that's a problem. Commented Nov 30, 2013 at 20:04

3 Answers 3

2

It depends on what youre trying to do. If you are looking to display a notification message or something similar then you should probably use setTimeout function. So It stops when its false or continues.

Also you should consider using GET instead of POST. Get sends one header and is faster comparatively.

Sign up to request clarification or add additional context in comments.

Comments

0

You may want to make the second call with a short setTimeout(). Other than that it is a pretty common technique, the only problem it causes, is to drive up your requests.

Comments

0

Sure it could cause a problem, constantly hitting your server with requests, which is compounded by the number of browsers or other clients that have that page loaded... If you're asking if it'll cause a problem for the browser, the browser won't particularly care that this is happening, you just may see increased wait times for those requests to complete as more clients are hitting your server constantly... To protect against this, I would recommend revisiting the rest you have this constant request hitting the server, and see if there's a better way to handle this sort of thing...

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.