mx:HTTPService calls are cached in IE 6 unnecessary
Usually, mx:HTTPService is defined in MXML in the following way:
<mx:HTTPService id="accountsRequest" method="POST" url="accounts.php" result="assignUsersData(event)" fault="onErrorLoad(event)"> </mx:HTTPService>
Such a HTTP request works flawlessly in Firefox browser, but in IE6 after first call the results of HTTP get cached and a new call to the remote destination never occur. The same issue is discussed at Adobe Flash Player 9 forums.My solution to prevent caching of HTTP requests in IE is to add foo variable to the url of HTTP Service that equals to the random value.
private function changePage(pageIdValue : Number) : void { var rnd : Number = Math.round(Math.random()*1000); accountsRequest.url = "accounts.php?foo=" + rnd; accountsRequest.send(); pageId = pageIdValue; }
2006
23
Nov
- Posted by JabbyPanda at 06:03 am
- Permalink for this entry
- Filed under: Adobe Flex
- RSS comments feed of this entry
- TrackBack URI
Great tip!
As you know, MXML is my preferred language. So I provided an example of your code using MXML. You can change the url attribute like so:
url=”accounts.php?foo={Math.round(Math.random()*1000)}”
[...] Another cause for this error in certain browsers is caching. Use JabbyPanda’s technique to prevent caching in IE6 or set the response headers in your server side page to prevent caching. [...]
Great Tip, Really useful as a quick solution!
This is also happening in apollo.
i’ve read in a comment on the adobe site by CNelissen that, for php, you have to use:
i’ve read in a comment on the adobe site by CNelissen that, for php, you have to use:
session_start();
header(“Cache-control: private”);
It really helps us. The HTTP services error happens sometime in IE and we have no idea to solve this untill find this tip. Since we cannot control the behavior in the sever side which is an external one.
you don’t need random at all just new Date() .toMiliseconds that it.
[...] cause for this error in certain browsers is caching. Use JabbyPanda’s technique to prevent caching in IE6 or set the response headers in your server side page to prevent [...]
Turns out that the PHP session_start() sets the “no-cache” as well. Had to remove this for it to work.
really great tip!! it works fine …
I would use Date() .toMiliseconds as suggested by levan.
There is a remote possibility that you may generate the same value twice with random (particularly if triggered at a regular interval). At least with Date() .toMiliseconds you can be absolutely certain then that the variable is a unique value.
Ant the way to get milliseconds is
Date().valueOf();
hi
i am getting the same error in IE as well as Firefox. I am using URLStream to load a page from a server. I get the first response just fine but in the second response i get the stream error mentioned in the post. Also i m coding in AS3, does the suggestion still hold in my case? And I am not sure if I randomize the url, i will need to make changes on server side too ?
I wasnt getting this error earlier, It used to work fine.
Please shower your useful comments.
Thanks
Hi Shrikant,
Yes my suggestion holds true also for fetching remote resources over HTTP by usong URLStream class
I used the date milisecond, which will always give me the new val and solved my problem!
Thanks,
Nilesh