开发者

Refreshing an XML file through HTTPService in Flex

I'm having a problem refreshing an xml file. I am bringing it in through an HTTP service component and putting it into a bindable array _cattArr, that I am using as the dataprovider for a grid.

When someone adds an item to the datagrid, it saves to the same xml file. Then I close the window, reopen it and don't see the item that has been added.

It is writing to the xml file, because when I re开发者_如何学Cstart the flex app, the item has been added, it's just not refreshing it. I have tried to resend the httpservice, but still no luck. What is the correct process for doing this?


My guess is that the browser is caching the file, after all Flex and the Flashplayer are using the browser as a basis.

On the server side you could try to set no cache headers - this depends on your server.

On the client side there's various things you can do:

  • Use a POST instead of a GET, POSTs are not cached
  • attach a "version" number to the query string: http://server/file.xml?version=1234. If you use a new version for each request, the browser has to download it and won't serve it from the cache.


As mentioned in the previous response, the easiest solution is to simply append a dummy random http param to the URL before making the HttpService call. e.g.

var hs:HttpService = new HttpService();
hs.url = "http://myserver/files/myXml1.xml?t=" + new Date().getTime();
//attach listeners to hs
hs.send();

This way you'll never get the cached xml from the browser. Thanks.


Always append a random number to get new xml file..

Atul yadav


I concur with the placing of a random param to the URL. I simply increment a variable every time a service is called (in the result handler), and embed the param to the end of the URL:

<mx:HTTPService id="getService" 
    url="http://serverpath/GetService.php?t={incNum}"  
    method="POST" resultFormat="xml" 
    result="getServiceResult(event)" fault="getServiceFault(event)" useProxy="false"/>

...
...

[Bindable]
private var incNum:int;

public function doInc():void :
    incNum++;
}

private function getServiceResult(e:Event):void {
    // get XML and disperse it to the UI
   doInc();
}
private function getServiceFault(e:Event):void {
    // report error codes, and fail gracefully
}

So for every service call, you could increment this number on the positive result. (You can do this on the fault result too, depending on how you want to structure things.) This will guarantee that the browser will always have to make a fresh, non-cached call to the database, and retrieve the newly saved data for your UI.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜