Limit To Number Of Post Requests (Javascript + node.js + jQuery)
NickName:Devin Lynch Ask DateTime:2013-03-12T00:09:50

Limit To Number Of Post Requests (Javascript + node.js + jQuery)

Basically I have client side javascript which sends post requests (through jQuery) triggered by user interactions with the page to my node.js server. The node.js server then handles the requests and updates content in the database.

For some reason, I am reaching a limit of the number of posts I can send to the server in a single page load. This maximum is 6. After 6 posts are sent from a page, I get these errors for trying to send any more requests:

EDIT:

These red errors are popping up in my Javascript console after trying to send more than 6 requests:

    send jquery-latest.js:8526
    jQuery.extend.ajax jquery-latest.js:7978
    jQuery.(anonymous function) jquery-latest.js:7614
    haveLikedOrDislikedObject
    (anonymous function) localhost:33
    fire jquery-latest.js:1037
    self.fireWith jquery-latest.js:1148
    done jquery-latest.js:8074
    callback

My code for sending the post: (Basically a listener is attached to numerous divs, and when it is clicked a post request is sent)

    //Sets on click listener for like button of content
    $(document).delegate("div[id^='likeDiv']", "click", function() {
        var el = this;
        $.getScript("public/javascripts/load_content.js", function(){
            haveLikedOrDislikedObject(0, $(el).attr('name'), theUser);
        });
    });

    function haveLikedOrDislikedObject(res, contentNumber, user){

        if(user != undefined){
            if(res == 0){
                $.post("/likeContent", { content: contentNumber, user: user.UserID });
                $("#haveLikedDiv_" + contentNumber).text("You like this.");
            } else{
                $.post("/dislikeContent", { content: contentNumber, user: user.UserID });       
                $("#haveLikedDiv_" + contentNumber).text("You dislike this.");
            }
        } else{
            $("#haveLikedDiv_" + contentNumber).text("Sorry, something went wrong.");
        }
    };

Just wondering why I would be getting this limit? Also, any thoughts on how I can go around this, or other ways to send numerous things to my server from a single page?

SOLVED: Turns out I was not sending back anything from my server and I think this means each post was waiting for a response, therefore making 6 open requests. So, make sure that you are sending something back from the server, even if it is undefined like this:

    app.post('/likeContent', function(req, res){
       res.send(undefined);
    });

Copyright Notice:Content Author:「Devin Lynch」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/15343295/limit-to-number-of-post-requests-javascript-node-js-jquery

More about “Limit To Number Of Post Requests (Javascript + node.js + jQuery)” related questions

How to limit the number of ajax POST requests?

I am using angular (in case it matters) and am trying to limit the number of ajax POST requests that my browser makes using javascript - ideally vanilla javascript on xmlHttpRequest object. Any ideas

Show Detail

Limit To Number Of Post Requests (Javascript + node.js + jQuery)

Basically I have client side javascript which sends post requests (through jQuery) triggered by user interactions with the page to my node.js server. The node.js server then handles the requests and

Show Detail

jQuery to limit number of http requests

I have been using 'snap widget' to pull a number of instagram photos into a page. However, it pulls 25 images in (which is a lot of http requests). I want to limit it to 7, but there is no setting ...

Show Detail

Is there a limit on the number of concurrent requests in DropWizard

Is there any limit on the maximum number of concurrent requests that Dropwizard can handle? Does Jersey have the same limit?

Show Detail

Limit number of requests at a time with RxJS

Suppose I have 10 urls, and I wish to make an HTTP request for each one of them. I could create an observable of the URLs, then .flatMap() the requests for each one of them, and then .subscribe fo...

Show Detail

How to limit the number of requests in a certain period in the class library?

I have created a class library which having certain methods that get and post the API request to a third party (Hub-Spot) so Hub Spot API has some limitations as follows ***15 requests per second a...

Show Detail

Limit Number of Requests for an IP in Strapi

I have a strapi app in which there is a collection called Page and I want to limit the number of requests to /pages . I know there is a rateLimit middleware but how do i use it and change its default

Show Detail

Django limit the number of requests per minute

I'm trying to limit the number of requests from an IP in case I get too many requests from it. For example: if I will get more than 50 requests per minute I want to block that IP for 5 minutes. Whe...

Show Detail

Limit the Number of Requests in Web Server

I am working in a web application where I am using the Tomcat as a web server. My requirement is to allow the maximum 100 requests at a time can be processd by my web application. And whenever

Show Detail

number limit of the request POST type signed call instagram

Recently I had a problem with a number limit of the request POST (delete comments) with API Instagram, it is only 15 per hour. I moved my application to signed calls I checked the option Enforce si...

Show Detail