0

Working on a platform, to enable auto-ticketing functionality. For which a REST API request is used for ticket creation. Unfortunately, there are 2 requests popping simultaneously, which results in creating duplicated tickets.

How to handle such case and send only one of these requests?

Tried adding the 2nd request in the response callback of the first, though this does not seem to work.

if (flag == 1){
 logger.debug("Node-down alarm-Request raised - +sitn_id);
 clearTimeout(mouseoverTimer);
 mouseoverTimer  = setTimeout(function(){  
 logger.debug("Inside Call back function - ");
        //function call for ticket creation
 incidentRequest(sitn_id,confUtil.config.mule_url);
}, 10);
            
           
NAVIN
  • 3,193
  • 4
  • 19
  • 32
renjini
  • 1
  • 2
  • 1
    can you check how those are triggered? – Rafee Sep 12 '18 at 01:50
  • What about handling multiple same request from different source? Only one request is send at a time via browser, though difference between those two might be in nanoseconds. Would recommend to handle such case at backend, and share more code that triggers multiple calls. – NAVIN Sep 12 '18 at 02:33
  • Are you putting this code inside a button event or some other clickable element? If you are not firing 2 requests maybe there is some event bubbling inside another element. Check putting a log after the `if' and see the console if there are two logs with one click – F.Igor Sep 12 '18 at 02:37

1 Answers1

0

You really should show more of the code that makes the request, though it seems as if you are doing some ajax inside your 'incidentRequest', so I will presume that (if that isn't what you are doing, then please, show your code....) - and since you tags say javascript and jquery - well, here goes...

To stop the 'double send' in an AJAX call, it is simple:

function incidentRequest(sitn_id,confUtil.config.mule_url){
    // stop the double by clearing the cache
    $.ajaxSetup({cache: false});
    // continue on with the AJAX call
    // presuming the url you want is confUtil.config.mule_url
    // and the data you want to send is sitn_id
     $.post(confUtil.config.mule_url, 'sitn_id=' + sitn_id, function (data) {
         // do cool stuff
     });
}

Hopefully that will help you get moving. If not, then we will need more code of what is going on around all this.

Apps-n-Add-Ons
  • 2,026
  • 1
  • 17
  • 28