Forum Discussion
There are no such restrictions, you can make any number of ajax call.
On that custom page, you are using a custom component having JS so in JS you can make any no of ajax call it does not depend on that custom page. LMK what you are trying to do so can help you out more.
i have a code where in i am processing bulk ideas , atleast 1000 minimum with updating some comments and changing status of them.
On a certain instance i am getting Error 429
https://httpstatuses.com/429
so i am unable to understand what is the cause of this error.
Is it because of too many calls ? . On some other instance i am not facing such issues.
- VikasB7 years agoBoss
I would also suggest you try it with few calls instead of too many calls. It would be great if you can share the code snippets.
As you mentioned that on some other instance, i am not facing such issues. It means the issue is not with multiple calls. You should reach out to support for instance-specific issues.
- Shivshankar7 years agoAce
request_str is string with 1000 ideas comma seperated.
var idArray=request_str.split(',');
var url1=endpointi?request_str="someId"&statusid="StatusId"&post_comment="postComment";
var saveData = $.ajax({
type: 'POST',
dataType: "json",
async:"false",
url: url1,
error: function (jqXHR, exception) {
//some code
},
success: function(resultData) {//somecode
}
});This code is giving error 429
- luk7 years agoBoss
This code can almost certainly not work, at least not in the way you provided the example, so giving you advice is hard here...
1. what are your "ideas"? are they integer ids, or JSON objects or something else?
2. if so, do you process each idea separately, if so, where is the $.each() loop?
3. You send a POST request and use a URL with GET parameters...just sayin'...
4. And of course you're getting a https://httpstatuses.com/429 error like this, no properly configured server should allow something like this, otherwise every 10 year old could DoS that server...
That means you have to properly set up a request queue that doesn't overwhelm the server with 1000 requests in less than a second... (use console.log() to see how quickly your code wants to send requests...), you can do that in various ways, I'm usually doing such things with a modified version of the ajaxQueue jQuery Plugin form here, it uses promises/deferred objects and I custom-added a delay option as I'm also using it to throttle requests sometimes, the modified plugin code is included below and after plugin code you find an example that you can run yourself (open the inspector > console to see what it does, but basically it delays each request for 1000ms = 1s):
(function($) { // jQuery on an empty object, we are going to use this as our Queue var ajaxQueues = [$({})]; $.ajaxQueue = function( ajaxOpts, queueIndex ) { var jqXHR, dfd = $.Deferred(), promise = dfd.promise(), ajaxQueue; // allow multiple queues that run independently of each other // specify the queue to be used like this (index can be ommited!): // $.ajaxQueue({<ajaxOpts>}, <int|queueIndex>) queueIndex = queueIndex || 0; // get queue index if specified ajaxQueue = ajaxQueues[queueIndex]; if ( ajaxQueue == undefined || !(ajaxQueue instanceof $) ) { ajaxQueue = ajaxQueues[queueIndex] = $({}); } // if there is no ajax request return an empty 200 code if ( typeof ajaxOpts == "undefined" ) { return $.Deferred(function() { this.resolve( [ '', '200', jqXHR ] ); }).promise(); } // run the actual query function doRequest( next ) { setTimeout(function() { jqXHR = $.ajax( ajaxOpts ); jqXHR.done( dfd.resolve ) .fail( dfd.reject ) .then( next ); }, ajaxOpts.delay||0); } // queue our ajax request ajaxQueue.queue( doRequest ); // add the abort method promise.abort = function( statusText ) { // proxy abort to the jqXHR if it is active if ( jqXHR ) { return jqXHR.abort( statusText ); } // if there wasn't already a jqXHR we need to remove from queue var queue = ajaxQueue.queue(), index = $.inArray( doRequest, queue ); if ( index > -1 ) { queue.splice( index, 1 ); } // and then reject the deferred dfd.rejectWith( ajaxOpts.context || ajaxOpts, [ promise, statusText, "" ] ); return promise; }; return promise; }; })(jQuery); $(function() { // just for demo purposes, this would be your $.each()... for (var i=0; i<10;i++) { $.ajaxQueue({ url: 'https://httpbin.org/get', delay: 1000 }).done(function(data) { console.log('success'); console.log(data); }).fail(function() { console.log('failed'); }); } });
Related Content
- 5 months ago
- 3 years ago