VBScript (Classic ASP ) and multiple ajax calls side by side - ajax

I have once ajax call which does connect to database, sets one flag in database and waits for one file to be created by some other process which looks up the flag.
Till the file is created on server, ajax keeps waiting. Once file is created, ajax reads the file and displays the content.
Now issue is that sometime the backend process which creates the file, stuck into socket issue, and never created the file, but ajax keeps waiting in that case, which gets timedout only when its timeout occurs,
What all I want to show a stop request button, which could stop current ajax request as timeout is long, and user could want to stop it prior to timeout.
Here is what I tried, I modified the code which keeps looking the existence of file, and added a session variable check , like if Session("AbortCheck") = true then exitout from the script.
and placed another ajax call to update the sessin variable so that on loop when the script will find session = true it will immediately stop the request.
While debugging I found that my my new ajax request which updates the session variable actually executed only when the first ajax is completed. and therefore its never stopped on user request to stop the request.
Could anyone let me know how to stop a running ajax (which is taking time) on user input ?
Thanks

Maybe you could implement some error management in your AJAX script instead of letting the user manages that.
'Try to open the socket here
on error resume next
if err<>0 then
Response.Write("1")
else
Response.Write(fileContent)
end if
Then you get the caller script notifies the error to the user if the AJAXs script returns 1.

I have fixed the server side execution by removing the loop from server side which continuously checks for file, and put a loop in js file to re check the same, and for handshake , if file is not found on server, I pass message as waiting to ajax and another flag for abort check from jquery, which solved the issue.

Related

ORACLE APEX 5.1 Error after process runs a long time

I am having an issue on a page which has a process that unfortunately runs a long time (4-5 mins). After the process I have a redirection to another page. What is interesting is that process actually finishes successfully ( but the sucess message doesn't show because of error) and the data is inserted etc. But the page does not redirect and I am getting this error on screen.
(http://prntscr.com/p79sfq)
There is no error message. When I inspect the page there is this: http://prntscr.com/p79u4g
http://prntscr.com/p79u4g
http://prntscr.com/p79uhh
The debug log does not show anything out of the ordinary:
http://prntscr.com/p79w48
Is the process or something timing out? Is there any setting or any way this could be prevented from happening.

Need to Update database when session expires or browser closed Codeigniter

I have table of 'users' having 'is_login' column. When a user logged in. 'is_login changes to 1' AND when log out 'is_login changes to 0'.
But if user closes browser, that 'is_login' column stays 1.
I need a method to update database, when session expires by closing browser.
I have tried this but not done:
How to exec a function when codeigniter session expires
I am open to other suggestions as well.
You would need to use some javascript/jQuery to catch when the browser is closed down and make an AJAX call to a script at your application that can set the logged in flag to 0. Using jQuery
$( window ).unload(function() {
$.post('location/of/your/script.php',{'identifier':'identifier_val'});
});
Then in script.php pick up whatever you post and act on it.
This is pretty unreliable in my experience and not a great experience for the user as this will fire if they reload the page. The other (equally nasty) way would be to use the heartbeat method. Essentially your jQuery needs to ping your server every minute. Then you would run a CRON job to check any user records that did not get a ping from the jQuery for more than 2 mins (or whatever you think is correct) and set those users to logged out.
Otherwise you need to open a socket connection with your server which is the proper way to do it.

MVC Ajax action completes if i break at first line then stop debugging

I'm using MVC4 and VS2012.
In my client code I have a jquery post that calls a controller action that performs a database update and returns a json result.
Everything works fine. However, if I put a breakpoint on the first line of my action method the program execution pauses there as expected. If I now click stop the program terminates as expected. However my database updates??? Using Fiddler I can see that the action is completing and a result is coming back from my action.
I am not double submitting the action or anything like that.
Is this the default behaviour. Is there a setting that terminates ajax request on stopping debug?
Regards
Phillip

Ajax Post Request blocks website loading

I have a strange problem with using ajax post requests. I use the request to run an ImageMagick process directly on the command line by using php function exec(). The process takes about a minute, and then responds with some variables. This is working fine, except from one problem. During the execution time I cannot excess other parts of the website that are installed on the same webserver (as if the server is unreachable). When the process finishes, everything works fine again.
I first thought this to be due to an overloaded server. However, when you access the website via another browser, there are no problems, even during the execution time of the process in the other browser. So it looks like the problems has something to do with browsers blocking other requests during the post request.
Could anyone help me out here? What could be the root problem?
Found the solution! Thanks from the help by kukipei By adding session_write_close(); to the file of the ajax request (after is has read the userid and token), the session file is no longer locked, and all pages are accessible again. Problem was that the session was locked during the whole execution time of the process, which was not necessary, since I only needed the session to read the userid and token. So before calling the ImageMagick operation, I now add session_write_close()

Long Poll and IE's XDomainRequest Object

I'm trying to implement a chat app that uses long polling to get messages from a remote (cross domain) server.
Is there any way to do this with a XDomainRequest? It seems my connections always get terminated after a random amount of seconds/miliseconds (usually about 1-3 secs) instead of waiting for the server to respond.
The IE dev toools thell me that the request has been "aborted" with no data received.
Is the XDomainRequest just not fit for long polling or am I missing something here?
Had this problem too, as a race condition, using the jQuery iecors library. The IE network console showed the request as "abort" despite Fiddler showing a 200 response.
After a few stubborn rounds of googling, I came across this link which recommends filling out all the callback handlers. I suspect that onProgress was only being called, and failing, when the request was slowed by a heavy page, leading to my race behavior.
IE9 XDomainRequest issued requests may abort if all event handlers not specified
For jquery.iecors.js, it was missing the onprogress handler, in addition to a few variable name typos. Adding this line seems to fix it.
xdr.onprogress = function () {};
For me the issue dealt with multiple query functions running as a single batch function using XDomainRequests. WebTools showed all requests to the remote server would abort but the last. Running with alert(query) before each query worked. So I ended up moving my XDR invocation (e.g. new window.XDomainRequest) inside the loop so a new instance would be created for each query to the remote server. Each result is inserted into an different input box via getElementById(id).value. With a delay timer added I can see it runs sequentially filling in each value now with no issues. Without delay it is virtually instantaneous.

Resources