window.location slow to update after change - javascript

Im experiencing an extrange behaviour with window.location :
I have an AJAX login, where the user gets redirected after login. The thing is that the process takes less than a second to call window.location='admin/newPage.php', but then the new page status on google dev Net screen says 'pending' for over 7 seconds, then it gets finally loaded.
The server runs fine, internet is fast and window .location gets called fast, I have tried on chrome and firefox and same problem on both ... so Im ruling out all this problems.
Anyone else has experienced this?

OK, I found the problem, Its actually the page being loaded after login.
This page has to run several server side scripts from the google server, then authenticate a user to get some google analytics data, and its being extremelly slow on that.
I just got very confused because the page didnt show for a long time. For me the spected behaviour would be :
redirect instantly -> show blank page for 7 seconds -> show contents
instead of
stay on login for 7 seconds -> show redirect page

After the page loaded again, javascript will trigger to load another page.
So it takes like 2x times to get to the destination if you use javascript redirection.

Related

Refreshing page via JS snippet

While testing a way in Firefox to reload an HTML page without caching, I've included the following snippet in my code:
<script>
window.setTimeout(function () {
location.reload(false);
}, 5000);
</script>
This reloads the page after 5 seconds, however I get shown the prompt: "To display this page, Firefox must send information that will repeat any action (such as a search or order confirmation) that was performed earlier."
If there a way to do a silent refresh via Javascript, one that doesn't show any prompt? For instance, if I used the refresh Meta tag (HTML), my browser silently refreshes. I want to approximate that same experience, but via JS (and no cache). BTW mine is a Django web app, and I inject the JS code in my Django template.
This is standard behaviour to protect people from submitting form information more than once (eg, prevent double payments in an ecommerce system). Try telling the Javascript to direct to a 'new' page:
Try using this, setting the url to your own;
window.location = "my.url/index.html?nocache=" + (new Date()).getTime();
Answer borrowed from here where there is also an explanation given for why this works -> How can I force window.location to make an HTTP request instead of using the cache?
Have you tried location.reload (true) ? If set to true, it will always reload from server. Set to false it'll look at the cache first.
You are getting this prompt because you ask to reload a POST request. You should always get this prompt when reloading a POST request, as it is not a safe method
However, if you wish, you can explicitely resend a POST request (though you might have difficulties to find back the POST data previously sent). Or explicitely send a GET request to the same URL.

window.location.reload(true) working inconsistently

I've been working on an automatic log-out functionality for my web page. As a part of that, I implemented the window.location.reload(true) in 3 different places in my code. Two of them are automatic, one is attached to a link. The link always works, but the automatic ones don't always work, and I don't understand why.
For the automatic logouts, one set by a debouncer:
var userActionTimeout = debounce(function(e) {
console.log("inaction timeout, reloading page");
window.location.reload(true);
},15000;);
$(document.body).on('mousemove keydown click scroll',userActionTimeout);
Which theoretically should reload the page after a certain amount of inactivity.
The other two uses happen after certain types of AJAX data submission (e.g. blatantly wrong data sent that could only happen if the client was modified) trigger a log out. Of course, any further AJAX submissions are ignored by the server, and the next page the server will serve the client is a login page. In the event this happened inadvertently, AJAX sends the client an error message that includes the following:
refresh to continue session
I also implemented a timeout that also happens if this link is served, which happens after the AJAX response is received:
if (typeof response._forceRefresh !== 'undefined' && response._forceRefresh) {
console.log('reload firing');
/*
some code to insert the link into a spotlight here
*/
setTimeout(function(){console.log('reloading in 3s...');},7000);
setTimeout(function(){
console.log('reloading...');
window.location.reload(true);
},10000);
}
However the issue I'm having is this: Most of the time, the debounce page reload works (tested in firefox & chrome), however occasionally it doesn't. The link always works, but the AJAX response reload is about 50/50. I know it receives the response from the server since the link shows up, but quite often it doesn't actually automatically reload the page.
What is going on?
When ever I get inconsistency on a web page, it usually involves caching that I didn't realize was happening. If you haven't already, look through your project with that in mind and see if there is an effected location that you can force it not to cache a page.
Another idea might be to try using the meta refresh element. There is another thread where this is suggested: auto logout idle timeout using jquery php

Poor Performance in Loading content using AJAX

I need your help badly in determining the cause of this problem. This is a hotel management system that keeps track of checked in guests and monitors them if their time is up. I'm using setTimeout as suggested by Mr. A. Wolff (Slow website after some time (with ajax interval of 10 seconds)) in this discussion. It's reloading the content every 5 seconds now but as you can see, the debugger is consuming 10 seconds in getting 56KB of data.
The problem still exists. I have done my researches about modals and timeouts and I am close to giving up. I just need a clue on where to start.
The computer is where the files are located. Technically, it's a server and at the same time, being used as a client for the system.
Here's a screenshot for the debugger. Thank you.
UPDATE:
I removed the setTimeout from the function itself so basically, nothing's reloading the page. Then I opened a checkin page, things got faster, and I mean so fast now. So I think this is what I need to do, I need to stop the function from reloading the page IF I OPEN A MODAL. The reason is that, if the modal closes, it's going to reload the PAGE anyway. So it must be a good idea to stop the recurring function when a modal is opened. Any suggestions?
UPDATE 2:
Here's the link of the script being executed:
https://www.dropbox.com/s/azi51w0pzp69kgh/checkin.php
Here's the live site: http://greenenergiesllc.com/temp
Login: removed by moderator
Password : removed by moderator
i suggest you don't use settimeout,use setinterval for 5 sec instead of it.
if you pull large data from server you must use json.
and also don't create js timer in same time,the server couldn't response over ajax requests.

Weird behavior with GET and POST

I am trying to use a web service in iOS to replicate the functionality of this form. I am running into a problem though. Anytime I send a post to it, I get an error saying
<html><head>
<title>410 Gone</title>
</head><body>
<h1>Gone</h1>
/prod/bwckschd.p_get_crse_unsechas been permanently removed from this server.</p>
</body></html>
When I goto this page and select Spring 2013, it takes me to this page. The problem is, the page 2 only loads if you went through page one to get there. How does the website know whether you went through there or not? I dug around and found it sends a POST request with the value p_calling_proc=bwckschd.p_disp_dyn_sched and p_term=201320(for spring 2013). When I send page2 this POST command I get the same results as if I just visited page 2 without visiting page 1: "/prod/bwckgens.p_proc_term_datehas been permanently removed from this server." I then thought I should behave more like a web browser and initially send a GET request to page one. When I receive a response, I should send a POST request with the aforementioned data filled in. When I do this, I still get the same error. Is there something I am not taking into account? All I want to do is send GET/POST requests so I can get a list of the classes being offered.
The second page basically sends a POST request to this page with the following variables:
term_in=201320&sel_subj=CS&sel_day=dummy&sel_schd=dummy&sel_insm=dummy&sel_camp=dummy&sel_levl=dummy&sel_sess=dummy&sel_instr=dummy&sel_ptrm=dummy&sel_attr=dummy
Can someone help me figure out how to replicate this behavior? I know very little about web development and feel like I am missing a key point here which is hindering me from finishing this app. Thanks.
Most likely the first page sets a cookie that the second page checks.

log out from browser if the browser closes in asp .net?

my requirement is bit of complicated .
an user is accessing the data base using the web browser, while accessing the data base if the user is closed the active page instead of log out the session - that session needs to be log out automatically.
can some one guide me how to make this ?
i am used jquery - in the master page.
onbeforeunload - i am getting message leave the page or stay with this page.
even i am getting this messages while login and and view the home page too.
This is the sample code
window.onbeforeunload = function () {
return 'You want to leave?';
};​​
see demo here
I think its possible to send an ajax request and you can saw your server that the user closed the browser's tab.
Also this a jquery plugin called jquery.idle, which is used to identify if the user is active.
Refer this Detecting idle time in JavaScript elegantly will gives you more idea.
You man close the browser or navigate to different page within website? If its closing the browser then the session automatically dies.
Also look into global.asax 's sesson_onEnd event.

Categories

Resources