Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are AJAX calls not blocking and what is their lifespan?

Tags:

jquery

ajax

I feel ackward asking these fundamental questions given that I am not exactly new to web development. But I want to double-check my assumptions nevertheless...

I'm building the recording of unique image views in my application. When a user (not a bot) visits an image page, an Ajax call is made to a back-end process that collects the session info, compares for duplications and stores the visit. I have all my javascript references as well as this call at the bottom of the HTML, just before the </body> element:

$.get(basepath + "image/1329/record/human", function(data){
console.log("Data Loaded: " + data);
});

By default, the call to $.get is made asynchronous. Yet I want to test the following assumptions:

  • Is it correct that this method ensures that the call to the view recording script is non-blocking for the rest of the UI?
  • Is it correct that the back-end script will finish once called, regardless of whether the user navigates to another page?
like image 977
Fer Avatar asked Feb 01 '11 19:02

Fer


1 Answers

According to jQuery .get reference...

This [$.get()] is a shorthand Ajax function, which is equivalent to:

$.ajax({ url: url,   data: data,  
         success: success,   dataType: dataType
});

And $.ajax is asynchronous (i.e. non-blocking) by default, that's what the A in Ajax means.

Also, back-end server code is started in the moment the server receives the request and then runs independently of the client staying on the page or not, unless you implement some kind of mechanism to stop the running service which I suppose you did not.

God bless!

like image 166
Trinidad Avatar answered Sep 19 '22 12:09

Trinidad