how do you make a synchronous server call (POST) via actionscript? I'm trying to execute a call on the browsers unload event - but I think it needs to be synchronous in order to get called.
As far as I know you can't make synchronous calls to server as in Javascript.
What I understand is that you want your swf to do a call to the server before closing the browser window - probably to log time used in a session
What you can do is the following:
IN FLASH: Add a callback function (A) in Flash using Actionscript ExternalInterface that does the following:
A) Does the call to server using URLLoader and specifying the method as POST.
B) calls window.close via ExternalInterface when the urlloader Event.COMPLETE handler fires
IN JSCRIPT: catch the onbeforeunload event of the browser and prevent it and call the call back function you defined in step 1 on flash to do the server call and then closes the window when it finishes the job.
Hope this helps!
Related
According to MDN:
The onfetch property of the ServiceWorkerGlobalScope interface is an event handler fired whenever a fetch event occurs (usually when the WindowOrWorkerGlobalScope.fetch() method is called.)
Does this mean that service worker can only intercept requests sent by fetch() from main thread? How about ajax requests? Is there any way to intercept them through service worker?
Fetch events are sent when any resource is being fetched through HTTP, be it scripts, medias, links etc., and XHR.
So yes, a ServiceWorker should intercept XHR requests (though synchronous ones are only intercepted in Firefox...)
I'm implementing an OAuth 2.0 login, which uses a server-side redirect to 'http://localhost/?code=abcdef' to pass the necessary data to the client application.
But the TWebBrowser.BeforeNavigate2 event is not fired in this case.
I've searched my head off, trying to find a way to detect server-side redirects (and handle them myself) within the TWebBrowser control (if possible at all).
As a workaround, I've implemented the TWebBrowser.NavigateComplete2 event. But because there's no HTTP-server running at the localhost (usually) this takes some time before it's fired.
I'd like to detect the redirect before the webbrowser tries to navigate to it and parse the data of URL myself and skip navigating to the localhost.
By default, TWebBrowser does not fire an event for a redirect. OnBeforeNavigate2 is fired for the initial URL before the redirect, and then OnNavigateComplete is fired after the redirect. You can compare the URL provided by the two events to know whether a redirect happened or not.
However, if you enable the browser's DOCHOSTUIFLAG_ENABLE_REDIRECT_NOTIFICATION flag, you will then get an OnBeforeNavigate2 event for a redirect, and can cancel the redirect if desired.
To enable the flag, you need to implement the IDocHostUIHandler.GetHostInfo() interface method.
If you are using 10.0 Seattle or later, TWebBrowser already implements IDocHostUIHandler for you, so just derive from TWebBrowser and override GetHostInfo() as needed.
Otherwise, for earlier versions, you can write a separate class that implements IDocHostUIHandler, and then you can query the browser for its ICustomDoc interface and call its SetUIHandler() method.
I am using Struts 2 in my web application with tiles also.I get data from simple get method from my action class. On page load in Firefox browser my get method execute twice while in network only single action call and in google chrome browser this method execute only single. What is going wrong in my web application.
I have a scenario where my rails controller action has to make a API request to a backend business logic server which does a lot of computations and returns me the result.
I'm thinking to show a loading page to the user and make the call asynchronous using Faye or any other option and redirect the user when the call is complete..
But even if I make the call asynchronous, the HTTP request needs to wait for the server to return the data after process, which would take around 20 seconds.
I would like to know what is the best way to make such calls in rails.?
I had faced a similar situation, below is the route that I took:
When the controller action is triggered
a. I fired off a 'async' request to the API using a worker(I used sidekiq)
b. Loaded a 'AJAX' spinner gif on top of a modal
The worker handling the API request runs on another thread which is synchronous and waits for the result from the API
When the processing is done, the worker fires off notification via 'Faye' which removes the modal and populates the data.
Return an HTTP response with status 202 Accepted(for the request that need to take long to process) and start making AJAX requests(to a URL, e.g /jobs/1) to check the status of the background job. Once your job has finished, update it's status so that your Javascript(AJAX) can handle the result of that background job.
I'm working on a web server built on Indy's HTTP server, and I've found that if I click on a request in the browser, and then on another one before the first one is finished processing, it can cause all sorts of problems. But I can't find any way to determine whether I'm in a canceled request or not. Each request takes place inside its own thread, so setting the thread to Terminated would be a good way to check, but that doesn't seem to be happening.
Is there any way I can get Indy to inform me that the request it's currently processing has been canceled by the browser that sent it and that it's now trying to load something different instead?
The only way a web browser can cancel an HTTP request in progress is to close its connection to the server. When that happens, TIdHTTPServer will raise an exception the next time it tries to access the disconnected socket. Just let the exception pass into TIdHTTPServer for default processing so it can terminate the calling thread and clean up the socket. This is normal behavior.