*sigh*
As programming techniques become more and more complex, and the programmers continue to be just as, or more, diversified, companies who insist on
being the industry standard while tossing away organizations such as the W3C, make life as a web developer increasingly difficult.
If that didn't make much sense, let me rephrase:
Microsoft still sucks.
Yes, this is my blog, and yes, I love Linux, so eat it.
Anyway... I've been working on a way to make a simple FAQ system I've been working on even simpler to use, and have thereby employed AJAX to maintain count of what people are actually looking at.
Without belaboring the details, suffice it to say that I have all the questions and answers on the same screen, but need to be able to quantify what people are actually looking at. In order to accomplish this, I hid the answers until users click on the question, thereby revealing the answers. At the same moment, I invoke an AJAX call to a PHP script which simply adds to a counter in a postgres table. Sounds pretty simple, eh'? Well, it was, for every browser on earth except Internet Explorer.
Problem: Internet Explorer would seem to make the appropriate AJAX call to the PHP script, and even report visually that it had successfully connected, executed, and responded. The problem with this was, the counter in the database would only increment the first time the AJAX call was made. Every subsequent call would result in nothing - even if the page was refreshed. The only solution I could find was to shut the browser down completely, and start it back up again.
It seems that if Internet Explorer has an AJAX script in it, which uses the same URL to call an external script, the AJAX only calls the external script the first time. Every subsequent time, the URL is cached, and no call is actually made - although no errors are reported.
This, of course, nullifies the very purpose AJAX is used! Thanks, Microsoft. Every other browser can do it. Why can't Internet Explorer?
Solution: The solution, for me, was really quite simple. Because the URL called was the same with each AJAX call, and it seemed this is the reason it was cached, I simply created another parameter sent via the GET method onto the end of the existing URL. Worked like a charm. Here's the code:
function sendRequest(id) {
var random_number = Math.floor(Math.random()*30000000000);
http.open('get','ajax/faq_counter.php?id='+id+'&random='+random_number,true);
http.send(null);
}
And that did the trick!
An extremely helpful link which ultimately helped me figure out what was happening can be
found here.
Hope this helps.