0

This is one of the interview question

For example :

Lets say there is a MVC application. In the View we have written a ajax method to call MVC controller

$("#SubmitCompany").click(function(){

   var jqxhr = $.post( "\Company\Save", function() {
     alert( "success" );
   })
  .done(function() {
    alert( "second success" );
  })
  .fail(function() {
    alert( "error" );
  })

   jqxhr.always(function() {
      alert( "second finished" );
   });

});

Where in Save method we have written a functionality to process the data and store it in database. We also return a bit whether it is successful or failed.

So the question is:

  1. What will happen if we initiate the request and close the browser after that?
  2. What will the output in this scenario (as per the Ajax call written)
HeyItsMe007
  • 101
  • 2
  • 8

3 Answers3

0

In my opinion if the request is made and sent to the server and suddenly the browser get closed then any changes will be made to server but there is no client here hence it just does nothing and no output will be made.

Another condition is that if the request is not made on server and browser get closed then it does nothing to both end.

Rohan Kumar
  • 40,431
  • 11
  • 76
  • 106
0

For whatever length of time that the client operator (program, and so on.) has completely sent the demand, the server has all it needs and will finish the demand and attempt to send back a reaction.

Indeed, this kind of "pinging" conduct is frequently utilized for "pulse"- like procedures that keep an administration warm or perform intermittent upkeep.

Alex Mac
  • 2,970
  • 1
  • 22
  • 39
0

IMHO, different languages have different ways for handling client connection states on the server. To answer your questions, it depends on how far the request has gone into server execution. If the server has all the input it needs to execute the request, then it will continue to do so.

However, if there are any reliable ways to detect the client has aborted in the middle of the execution, then whether to continue or abort further execution can be decided with the server code. I'm no .NET expert but from this answer, it looks like you can use Response.IsClientConnected to identify if the client browser aborts the request and decide the course of action and output.

In PHP for example, a connection status is maintained. There are 4 possible states based on which you can decide whether or not you want a client disconnect to cause your script to be aborted.

Sometimes it is handy to always have your scripts run to completion even if there is no remote browser receiving the output. The default behaviour is however for your script to be aborted when the remote client disconnects.

Joey Ezekiel
  • 1,017
  • 1
  • 11
  • 26