I am writing some js code to send user-page interaction data to analytics server. I am in this context:
No Google analytics.
No third party library.
And I need to achieve:
shouldn't block user navigation. (or as invisible as possible)
should ensure each request is sent to the server.
should be universal, not servlet solution for one site.
Currently what I observed from making a normal AJAX request is when I navigate to another page, the request is canceled from browser side, which indicated data loss.
Any comment/answer is welcome.
Related
On an order confirmation page I am making an AJAX request to a page that has a javascript code that tracks cookies and records data. When I fire the request to the other page with the javascript code nothing seems to be happening.
Is this because javascript is executed on the client side and the AJAX request is only getting the server side response?
Thanks,
Yes that is correct, in order to fire the javascript code on another page you have to load the page.
There are a couple of (dirty) tricks to do this and I would recommend not using any of them.
Your best call is to load the cookie from the order confirmation page (which is origin based, so can be used on other pages on the same domain)
I have the following situation: A frontend server redirects with HTTP Post to a backend server. At entry of the backend server, I execute some PHP code before the page has been loaded. I would like to send a notification, at this point, back to the frontend server that the redirection was successful.
The entry page on the backend uses the Post/Redirect/Get pattern to prevent browser form resubmission alert, so after this the PHP code does a HTTP Get request to itself. After the Get header has been sent, the notification back to the frontend should not be sent from PHP code, to prevent sending it each time the page is refreshed on the backend server.
Can this be done from PHP code, or do I have to wait until the document has loaded and then use an Ajax call from Javascript and somehow check that the notification is only sent once (the first time)?
After all processing was complete, your backend server could redirect back to the front-end server, with any custom data to be passed either as POST vars or url parameters in a GET. The front end server would then handle the UI display of this custom data.
But I think thats a sloppy design... systems should be segregated not just for security reasons, but also for scalability. The best design IMHO would be to make bi-directional AJAX calls between your "frontend" web server to a firewalled, "backend" system.
I have a page that makes a cross site request to another application to gather some details.
One page in the app succeeds in making this GET request. This page, by and large, just displays the details that come from that request.
Another page in the app fails to make the GET request (the browser aborts the request). This page displays the same details as the first page, but also has several additional UI elements.
The pages are from the same app, they have the same domain and protocol. The only thing different is the path of the page.
Specifically, I have:
Working Page: https://outreach.example.com/members/32234254
Failing Page: https://outreach.example.com/cases/9975
Both pages are making a request to:
https://crucible.example.com/api/members/234ABE2342349.json?token=valid_token
The Access-Control-Allow-Origin header is being returned with the value: https://outreach.example.com
The AJAX requests are identical and Fiddler clearly shows both succeeding; but IE aborts the request coming from the failing page.
In both cases, the pages have a client side UI generated by knockout.js. The biggest difference is that the page that succeeds doesn't start rendering until the request returns, while the page that fails is rendering while the request is pending.
Is the XDR sensitive to other DOM or javascript activity in the browser? The best discussion of XDR that I have found is here, but it doesn't mention anything about this. There's also nothing about this in the XDR documentation.
Are there steps that I can take to ensure that my requests are not aborted by the browser?
Imagine I have a public display, showing a browser displaying a web page.
Is it possible to send a GET or POST from a mobile device to an HTTP server which triggers some AJAX/pubsub/websocket JavaScript function that changes the page that is presently being viewed on the display, or even just changing an iframe's current domain?
Cross-domain pushstate? Is this at all possible even on your own setup?
Assuming you control the web page being shown on the public display, yes.
The web page would need to either periodically contact the server via AJAX, or have a long-running connection to the server (i.e. Comet or WebSockets).
When the server receives the request from the mobile device, it either uses the Comet connection to send the new URL to the web page, or when the web page next contacts it via AJAX, it sends the new URL in response.
The web page then sets its own window.location property to this new URL.
Note that once it's done this, you'll no longer be able to send the browser in question to another new page, unless the page that you've just sent it to also includes the JavaScript that contacts your server.
But if you don't control the web page being displayed...
Then you'd need a browser extension to initiate the connection between the browser and your server.
You can do this with JavaScript on the client side. This is covered pretty well in that question: Updating address bar with new URL without hash or reloading the page
Unfortunately, it's a relatively new, and mostly unsupported feature. Your alternative is to set the hashtag and use it for navigation.
UPDATE:
If you are trying to "push" pages to the user like a TV channel, then you can have an AJAX request poll the server every few seconds to see if there's a new page. The server would respond with the new URL. You could then put that page in an iFrame.
I was learning about custom protocols for few days, and there's one thing that I don't understand.
I know how to start an app with custom protocol, but My question is,
Is it possible to get apps response and print it in Web Browser using javascript?
For example If I will send request to protocol myapp:// , that will open an app written in C#, and that app will return string "This is response" can to print it in Web Browser?
If so, can you help me to accomplish it?
Thanks in advance.
Internet protocols aren't all about browsers.
mailto: causes an action in an email program (e.g. start a new email)
ftp: causes an action in an FTP program (which might be integrated into a web browser or Windows Explorer)
gopher: (well, that's not really prevalent anymore)
myapp:// will cause your (C#) app to start running. At that point, it can do anything a C# app can do. One thing it could choose to do is create a .html file on disk, and use
Process.Start("file://Path/To/My.html")
to cause the default web browser to open the document it just created.
UPDATE
You can certainly have your myapp:// protocol handler send an update to the web server that hosts the page in question. My assumption here is that the myapp:// handler is running on a client machine, and there is a web server on a different URL http://mydomain.com serving a page that includes a myapp:// reference.
Web server renders a page that includes both a myapp:// URL and Ajax code to periodically query the web server for updates to part of the HTML body.
User clicks the myapp:// URL
Protocol handler runs
Protocol handler sends an update to the web server, e.g. http://mydomain.com?user=joe&result=123
Web server uses ?user=joe&result=123 to update response next time the Ajax callback is initiated
Ajax callback gets updated data for page from web server, updates page.