ajax call and page redirection - ajax

I am making a ajax call in a page. Before getting the ajax response,
if user navigate to other page,
will the ajax call will be completed?
page loads
user doing some action, which making ajax call at
background and updating in server.
before ajax call gets response,user navigated to some other page.
Will that ajax call will be completed?
Thanks in Advance!!!

No. Whatever action the ajax call initiates on the server will probably finish (ie, the php script), but the browser will not receive the response.

Related

Laravel AJAX call response is redirect to login page

I'm using AJAX. I call the server which calls an API and gets its response. I try to return the response in JSON to the client. But my Laravel has Middleware that checks token is valid. And when it's invalid, it'll redirect to login page. So the response I return is not JSON from API call but is the HTML of the redirected login page. I don't know what to do about this. One, the response is not the expected JSON and two, how do I keep the mechanism of redirecting to login page when the situation is an AJAX call and not the usual going from one page to the next.

Grails 2 - Too many Ajax calls will invalidate user sesssion

*update: sorry, i didn't give a context. I'm using Grails 2.1.2 with the spring security plugin installed. Js lib -> jQuery (latest)
I have a page that submits lots of synchronous ajax calls (not my design, sorry). After the 25th call i see from firebug that i start getting http 302 status, then the handler for ajax calls when there's no user session is called (loing/authAjax in my case). My particular handler sends an http 401. In any case why is the session expiring? This happens only when i submit tons of synchronous ajax calls. Is there any limit to the number of ajax calls? Is it documented anywhere? Making async calls is not an option in this case because these ajax calls make db updates on the same table and that would result in a hibernate lock exception.
I'm not asking for a fix, i know how to fix this (by doing one single ajax call). What i'm asking is why the session is being invalidated? Any ideas?
Did you try to set the cache setting to false in your calls with jQuery ?
302 means you're getting data from the browser cache instead of the server.
Hope this help....

Abort the execution of a ajax request

I am sending an ajax request which is called on change event of a select box.Now what I want is that when a new request is sent to server, it will abort all the previous ajax requests as otherwise there will be a lot of ajax requests executing at the same time.I just want to execute only the latest request.
All help would be highly appreciable.
Abort Ajax requests using jQuery
Just store the XMLHttpRequests in an array and abort them one by one.

Prevent IE7 from treating cached ajax response synchonously

IE7 appears to be caching the response from an ajax request. When the response is cached, it behaves as if the request is synchronous, calling my callback as soon as it is passed to jQuery.get, rather than waiting for the current call stack to return.
For now I'm going to put a short timeout in my callback, which will hopefully get my code to work at least. Is there a better way to prevent this from happening? To force IE7 to wait until the current call stack is finished before calling the callback?
Here's a simplified example of the behavior I'm seeing:
myDebugger.log("setting up ajax request");
jQuery.get(myUrl, function(){
myDebugger.log("ajax request returned")
});
myDebugger.log("finished setting up ajax request");
The first time I run this in IE7 after restarting the browser, I get:
setting up ajax request
finished setting up ajax request
ajax request returned
The second time I run this in IE7 I get this:
setting up ajax request
ajax request returned
finished setting up ajax request

difference between ajax and form submit

I just want to know what is the difference between sending parameter with ajax(post/get) to a servlet and sending them with "submit" .
Thanks for your help.
A standard form submit sends a new HTTP request (POST or GET) and loads the new page in the browser. In Ajax, the data is sent to the server (POST or GET) in the background, without affecting the page at all, and the response is then received by javascript in the background, again without affecting the page at all.
(The javascript can, of course, then use the data received from the server to update some of the page content.)
Ajax is generally useful where only a small section of the page content will change.
At the simplest, with ajax, you don't witness page refresh while submitting form data. And if you don't use it eg you use submit buttons, you witness page refresh. Both submit the data.
Server side handling of both are exactly the same. The server is not concerned about how the post request is made.
The difference is in how the browser (client side) responds to both the actions. The browser usually decides to make a request for an entire page if it is a form submit; otherwise, it just updates a part of the page.
From the servlet's point of view there is no difference. For the client, a submit will load a new page, while an Ajax request will parse the response with javascript code and act accordingly.
The form submit will reload the page that you are working on client side.,while in ajax call the call was made to server will not reload your client side page

Resources