views:

40

answers:

1

I'm using mx.rpc.http.HTTPService to retrieve data from a web service. On the initial call to "loadWsData", HTTPservice accurately retrieves all the data.

However, on any and all subsequent calls HTTPService does not accurately retrieve the data; rather it always retrieves the first data set. I've confirmed that the web service is providing accurate data, both from web browsers and a ruby ws client script.

My code is below; any ideas on what could be the problem?

private function loadWsData(id:int):void
{
    var webService:HTTPService = new HTTPService();
    webService.url = "http://xxx.xxx.xxx.xxx:8080/profile/ + id;
    webService.method = "GET";    
    webService.addEventListener(ResultEvent.RESULT, function(event:ResultEvent):void
    {
        var rawData:String = String(event.result);
        var user:Object = JSON.decode(rawData).user; // User object always reflects the first data set retrieved.
        ....
        ....
    });
    webService.send();
}
A: 

Not sure what the issue might be, but I have a few suggestions on where to look.

First, there appears to be a bug in your code; the webService.url line is missing a quote mark. That could be messing up the URL you think you are sending. Odd, though, because I don't think what you have shown would compile, so I suspect this is just a cut-and-paste error when you posted this to StackOverflow, but I would trace out that URL just to be sure.

Also, I don't see code to remove the event listener (although it could be in the code you have abbreviated with ellipsis). Is it possible that there are lingering event listeners that are firing in addition to the ones you expect? If the original event listener fires, it will fire with the original data.

Another suggestion: instead of using a closure, try pulling it out to a separate function. That shouldn't be the issue, but maybe scope is playing a role here.

You could try to POST your results.

You might also add an event listener for FAULT, and see if there are any errors being thrown by your service request.

cc