Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Fire a one-way ajax call

I have a WCF service which takes a long time to process the first time it is called, and then caches those results in HttpRuntime.Cache. In order to initialize this cache I'd like to trigger a fire-and-forget ajax call from javascript.

Right now I have this javascript in the page:

$.ajax({
    type: 'GET',
    url: getServiceURL() + 'PrimeCacheAjax',
    contentType: 'application/json; charset=utf-8'
});

Where the PrimeCacheAjax function just performs a dummy call to populate the cache.

The only issue with this approach is that the page with this ajax call is a type of landing page which executes some javascript, opens another window and closes itself. When the window closes itself before the server responds, I see a cancelled request in fiddler. I am concerned that this may lead to situations where the ajax call may not reach the server, is this possible?

Is there a way to specify (using $.ajax()) that no response will be coming, or does it not really matter?

like image 314
jbabey Avatar asked Dec 11 '12 19:12

jbabey


People also ask

How do I fire AJAX request periodically?

Use setInterval() when you want to send AJAX request at a particular interval every time and don't want to depend on the previous request is completed or not. But if you want to execute the AJAX when the previous one is completed then use the setTimeout() function.

How would fire a callback when any AJAX request on a page has completed?

How would you fire a callback when any AJAX request on a page has completed? The ajaxComplete() method specifies a function to be run when an AJAX request completes. Note: As of jQuery version 1.8, this method should only be attached to document.


1 Answers

Only time it will matter is if the request to the server is not complete. You should check to make sure the call is at a readyState value of 2 [aka sent], before exiting.

like image 178
epascarello Avatar answered Sep 24 '22 09:09

epascarello