I've a login form of a website running IIS/Asp.net which during booking times because extremely sluggish.
At the LOGIN PAGE I'm doing:
$("#submit1").trigger('click') //this will login into PAGE1 using form.submit()
setTimeout(function(){
window.location = "/PAGE2";
},500);
PAGE1 has a GET link to PAGE2.
All I want to know whether it will take me to PAGE2 or PAGE1 ?
Because the IIS server will first process the form submission and send the PAGE1 content. Then it will send the GET request PAGE2 content.
How will the browser(Chrome & Firefox) behave? If it first received the POST response then will it discard the PAGE2 GET response?
Or will it overwrite the POST response(PAGE1) with the GET response(PAGE2)
Assuming POST response(PAGE1) is received and now site is showing PAGE1. After 1 minute the GET response(PAGE2) is received. Now what will the browser do?
I want to depict the sequence(which is example case):
in other words what i understand your question is "which page will my browser load?"
The broswer will Load whatever the most recent request it makes.
if your button click request longer than 500 miliseconds to load a new page resource the button click request should get overwritten to load page 2. If the page loads before 500 miliseconds then it should load page 1.. its a bit like asking what happens if i type www.google.com in my address bar press enter and then enter www.facebook.com... which resource do you think will load?... The most recent request that you make.
By the way window.location = '...' will do a server request just like your asp button click does.
I recomend that you open up google chrome network tab and investigate/observe what calls you make to the server in what sequence...
The code
$("#submit1").trigger('click') //this will login into PAGE1
setTimeout(function(){
window.location = "/PAGE2";
},500);
This will trigger the click event on the element with id submit1. Assume it is a button for login.
Then
There are 2 possibilities because you didn't mentioned whether this is carried out via Ajax or not.
If you used ajax, then if the login process completed within 500mS, then you will successfully log in to PAGE1 and redirect to PAGE2. Because it is ajax.
If you didn't used ajax, then the code
setTimeout(function(){
window.location = "/PAGE2";
},500);
will be ignored. Because at the first event itself, it will take you to PAGE1and the life cycle of this script from Login Page will end. So, you won't get to PAGE2. If you want to go to PAGE2, then you should add the above mentioned code in PAGE1.
Note
The request GET and POST can't do anything with the life cycle of a script if it is not made via Ajax.
Update
No. Both POST and GET won't trigger at a time.
First the POST will trigger.
If it first received the POST response then will it discard the PAGE2 GET response?
Yes
Because the GET request is made from login page and as a result of the POST message, you are already redirected to Page1. So, the GET response won't even catch by the browser.
Related
I want to redirect user after clicking a button by ajax response sent after clicking a button.
I tried with amp-form but seems it does support ajax.
Flow is:
User clicks a button
Ajax request sent
Ajax response received with url to redirect and message
Message shown to user for 5 seconds, and after 5 seconds he is been redirected to the url.
This is simple to set in regular JS, but I didn't find how to achieve this with amp.
How can I redirect with amp after button click by the ajax response?
I am trying to make a button cancel a document request from the server while it is loading, I've tried window.stop() on Chrome but it does not prevent the page from reloading. I've also tried those lines but they get me back a blank page, which is not what I want, I need just to stop the request, as if pressing the Esc key.
document.write('<script type="text/undefined">'); or
document.write('<!--');
When I click the button and immediately press the Esc key I get the result wanted
edit: coming back to this question after some time, what I meant was actually:
"How do I prevent a request from loading the response sent by the server in user side"
We really need to see the code you are using to initiate the "document request from the server".
Here is a cool way to cancel if you are doing this type of request.
What about using abortable-fetch.
Nice demo here.
The solution to my problem was redirecting to:
http_response_code(204);
So the page stayed as it was before making the new request and but I was still able to use it normally. Thanks to those who answered anyways, the abortable fetch was also an solution.
My goal is to make a modal window popup if a user clicks on a link to a page (or POSTs a form) for which he is unauthorized, as it is a better user experience than redirecting to a generic error page.
What I did is implement
protected override void HandleUnauthorizedRequest(AuthorizationContext filterContext)
{
// ...
}
so that if the request is a non-AJAX request then it redirects to the same page (gives the illusion of staying on the same page) and appends the query string with "forbiddenRedirect=true" and then JavaScript opens the error modal. I'm trying to think of a better way than using the query string. From what I can tell, there's no way for JavaScript to access response headers, only the URL. That's why I went with the query string solution. But maybe in MVC there's some way I can redirect and pass some sort of token that the base controller can recognize and then add something to the view bag like ViewBag.IsRedirectFromUnauthorizedAction = true.
Any suggestions?
The user should never get to a page where they can post data without being authenticated and authorised!
If your users can get to forms where they can post information (lets go with a User Profile Page), they should be authenticated before they can even get there. So for example, you would lead the user to a Log in page before you allow them to access the Edit Profile page. Once they have authenticated themselves and you have checked they are authorised to perform a POST on a particular page, then you present them with the form.
But what if their session times out?
In the event that the user authenticates and gets to that page, then their session times out, you should redirect them back to the Log in page where they are prompted for their credentials again and deny their post request. In an ideal scenario, you should have an AJAX function running in the background every 30 seconds or so. If they are idle for a set period of time (lets say 5 minutes) then you can assume they have closed the browser or left their PC unattended. At this point, either ask the user (via modal window) if they'd like to stay logged in or be logged out in 30 seconds. If they click the Stay logged in button, leave them be. If they don't answer, you can log them out and automatically redirect them back to the Login page.
Sorry, I didn't know how to put the question better. Basically, what I want is, if 2 similar ajax calls are fired before the 1st is finished, instead of sending the second one, just wait for the first one to complete and use that result.
As an example, you can think of an app, which requests Facebook news feed.
User goes from home screen to news feed page
ajax fires to get news feed content from Facebook
user clicks back button, which takes him back to home screen before ajax call is finished
user clicks on news feed again
ajax fires again to get news feed
meanwhile the first request comes back, but is no longer used, because the app is now listening for the second request, which is almost identical
I am saving the news feed content so that I can show it next time user comes to that page, while sending ajax call to update the content. But in the above case, the second time user comes to the page, the values are not saved yet, hence nothing to show before second request comes back.
Assume that it's a one page app, so we don't lose state.
I know it requires good amount of thinking. Any ideas? at least in theory?
Set a global variable = 0 when the page loads. When a request is triggered - if the variable != 1 - fire off the request. Once you have retrieved the requested and output the results; set it back to 0.
Assuming we don't lose state store the results of the ajax call somewhere and when the news feed is loaded again check if the results already exist before making the request again.
There is a form ,which is submitted and then the page is redirected to another page.But if the user hits the refresh button again on the new page .the following message is displayed
To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier.
And on press "OK"
A duplicate entry is created how do i prevent this or how do i handle this
I am using a django,application
Thanks..
I would double check your sequence of events because it seems like something is off.
It sounds like you're processing the post data, then returning an HTTP response rather than a redirect. When your user refreshes the page they resend the POST data.
I'm wondering where and when are you processing the POST data and if you're correctly redirecting.
The page that the form submits to should process the POST data and create an entry (sounds like that is working).
If you want to avoid having the double post issue on a successful submission it's best to redirect to another page AFTER you've processed the data and successfully saved.
This will not pass the POST data to the new view, and the user can refresh the page to their hearts content without having to worry about double submissions.