return to I Love My Journal
A Little Closer to Center...
Musings about Life, Linux, and Latter-day Saints.
Pages
About Me
Links


Tags
PERSONAL 520
SPIRITUAL 416
LDS 312
BOOK OF MORMON 237
SCRIPTURES 154
STUDIO-JOURNEY 129
RELIGION 112
LINUX 79
COMPUTERS 65
LIFE 60
GENERAL CONFERENCE 46
GENTOO 39
MISCELLANEOUS 37
MUSIC 37
PROGRAMMING 33
CARS 29
MICROSOFT 23
FAMILY 23
AUDIO 21
I LOVE MY JOURNAL 18
FUN 15
CHILDREN 12
CURRENT EVENTS 10
NATURE'S WAY 10
VIDEO 9
DRM 9
CONEXM 7
BABBLINGS 7
PROVO CITY CENTER TEMPLE 6
FRIENDS 6
HEROD THE FINK 5
GAMES 5
COMPUTER HARDWARE 5
DRUMS 4
HAND OF GOD 3
ADVERSITY 3
KDENLIVE 3
AUDIO HARDWARE 3
GENERAL INSANITY 3
STUDIO 3
THANKS4GIVING 2
CATS 2
MY JOURNAL 1
POETRY 1
FOREVERGREEN 1
EVERYDAY THOUGHTS 1
GOSPEL 1
PARENTING 1
YOUTH CONFERENCE 1
CHURCH NOTES 1
POLITICS 1


RSS Feed

RSS FeedSubscribe!
Mon - Oct 20, 2008 : 03:14 pm
annoyed
   rated 5 times
>>next>>
<<previous<<
IE Caching AJAX bug
*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.
Comment by john palmer on Nov. 21, 2008 @ 06:09 pm
Thanks so much for this post.

I spend the better part of a day trying to get AJAX to work in IE.

After reaching the point of major frustration, I tried it in Firefox.  Worked just fine.

A google of 'IE AJAX bug's led me here to the solution.

I can now go enjoy my weekend.