[英]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. 基本上,我有客户端javascript,它通过用户与页面的交互将触发的发布请求(通过jQuery)发送到我的node.js服务器。 The node.js server then handles the requests and updates content in the database. 然后,node.js服务器处理请求并更新数据库中的内容。
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: 最大值为6。从一个页面发送6个帖子后,由于尝试发送更多请求而出现以下错误:
EDIT: 编辑:
These red errors are popping up in my Javascript console after trying to send more than 6 requests: 尝试发送6个以上的请求后,这些红色错误在我的Javascript控制台中弹出:
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) 我发送帖子的代码:(基本上,侦听器已附加到多个div,并且单击后会发送一个帖子请求)
//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. 已解决:事实证明我没有从服务器发回任何东西,我认为这意味着每个帖子都在等待响应,因此发出了6个打开的请求。 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);
});
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. 原来我没有从服务器发回任何东西,我认为这意味着每个帖子都在等待响应,因此发出了6个打开的请求。 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);
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.