An easy way to log client side information to server
What should we do?
The first thought comes into our mind may be using AJAX, since it involves client server communication and we also should make it asynchronously because we don't want to interrupt users while we are logging something to server. This is feasible, but it needs many codes to be written to create the XMLHttpRequest object and implements some function related to it, it is also error prone since the communication may be interrupted as well.
1. We need to create a backend server script to get the passed query strings and store them on the server. We assume it is logger.php here;
var img=new Image();
3. Call the log() function like :
That's all. You can simply log information to server now.
In the log() function, we created an Image object, it is supported in all modern browsers, later when we assign the src property, the image will be loaded immediately. this will load the logger.php script with the passed query string. It has similar effect as the AJAX method.
- The Image object is available in all browsers, even those that don’t support the XMLHttpRequest object.
- Cross-domain restrictions don’t apply. Often there is one server responsible for handling error logging from multiple servers, and XMLHttpRequest would not work in that situation.
By clicking the "Mark as important" button, this article will be put to your important article list which you can find in "Amin->Article important list". Later when you want reread this article, it's easier for you to find it by checking the "Article important list".
::Comment Zone (Total 0 comment)
:: Other versions
No other versions available yet.
:: Recent articles
- HeartBleed: OpenBSD now starts to clean up OpenSSL
- HeartBleed: Should C be blamed for the HeartBleed bug?
- HeartBleed: Inside the heart, what happens to a normal WEB user?
- Learning Python as your first programming language
- PHP Apache MySQL Set-up Note
- Hey, you may be happy to know these mottos about programming languages
- Tips for a better first-time hackathon experience
- <=> operator in MySQL
- Why does LinkedIn migrate to NodeJS from Ruby?
- more ►
:: Most read
- Cross Browser HTML5 Drag and Drop
- Sony is to release PlayStation4 in 2015
- GCC is compiled with C++ compiler
- TIOBE : C overtakes Java as the No.1 programming language
- 5 Free Open Source Chat Applications For Developers
- Which programming language should I learn first?
- Disposable Email address
- Why PHP is (so much) better than Ruby?
- Is Ubuntu becoming a big name in enterprise Linux servers?
- Great code is written twice (or more)
- more ►
:: Find us