$. ajax locking the server

Asked

Viewed 258 times

0

i am trying to make an app with phonegap and am having the following problem.

As an example, I have the following function:

function listar(){

    var useremail = localStorage.getItem('email');
    var userpassword = localStorage.getItem('pass');
    var acao = "listar";



    $.ajax({
        type: 'POST',
        url: 'http://www.site.com/funcoes.php',
        data: {useremail : useremail, userpassword : userpassword, acao : acao},
        beforeSend: function() {
            // Loading function...
            document.getElementById('loadfunc').style.display = "block";
        },
        success: function(data) {
            $("#wrapper-home").html(data);
        },
        error: function(xhr) { // if error occured

            alert("falha ao carregar");      

        },
        complete: function() {
           document.getElementById('loadfunc').style.display = "none";
        },
        dataType: 'html'
    });


}

I was testing the following - I click on the button that calls this function and when I finish pressing I click again. After clicking a few times it starts to fall into the error function.

Funny that using my pc as a server I click endlessly and there is an error, just went to the hosting service and started giving the problem.

Would anyone have any light on what it might be? Something I can add in the function to know the exact error you are giving or even some configuration on the server that needs to be done. (I’m using the godaddy).

Thank you!

1 answer

0

What kind of server are you using ? shared hosting, VPS, dedicated server ?

It may happen that the server interprets all these requests as a Ddos attack, so to prevent it does not allow access, but there may be many other reasons for this. So do the following, la in your error Function puts so to show what the error is and see what it is returning:

error: function(xhr) { // if error occured

        alert(JSON.stringify(xhr));      

    }
  • I’m using shared hosting, I imagine. It’s the simplest. Changing the error function, I have the following message: {"readyState: 0,"responseText":"","status":0,"statusText":"error"} Any idea what might be?

  • @rhundler A few days ago I went through a very similar problem, even returning the same error, but the difference is that it did not run either on the local server or in the VPS. So I replaced $.ajax with $.post, made the necessary changes and is running thin. But I think this is not your case, since it works and stops working after a few requests. When you use the same code in the browser but request the hosting ( the same way it is in the application ) the same problem or works right ?

  • I just tested by the browser and the same problem happens. Only the alert does not appear with the error.

  • I did a search and it seems that a user has reported that in godaddy’s shared linux hosts ajax is not enabled. What is strange is that mine works for a period of time and then hangs.. In case, I changed to windows and the error is no longer caused.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.