Expand my Community achievements bar.

HTTPService - Datagrid DataProvider

Avatar

Former Community Member
Hi,



Basicly here is what I'm trying to do.



1. Load XML (Through PHP)

2. Populate Datagrid with data

3. Use UI button to refresh datagrid with XML



Load XML,, I'm using HTTPService to load the XML which i
generated with and PHP File which is loaded from mySQL. This works
fine, I initate an function from creationcomplette in the
application tag..like so:



public function loadData(e:FlexEvent):void{

test.url = 'test.php';

test.addEventListener(ResultEvent.RESULT, resultHandler);

test.send();



}



This works great :) The ResultHandler populates the
dataprovider of the Datagrid like so:



public function resultHandler(e:ResultEvent):void {

myDG.dataProvider = e.target.lastResult.book;



}



Which also works great..



Then I have the button to get the newly inserted "books" in
the MySQL that "should" refresh the Dataprovider like so:

public function reload(e:MouseEvent):void{



test.addEventListener(ResultEvent.RESULT, resultHandler);

test.send();



}





But here is my problem the only thing that is happening is
that the test.send() is fired, but the .lastResult is still the
same length and the same object as before even if they have doubled
in the PHP (XML) file.



Could anyone help me please?

3 Replies

Avatar

Former Community Member
I'm a bit of a novice at Flex but it seems like you don't
need to add the event listeners.



I'm just guessing but I assume you have
<mx:HTTPService> tag that identifies the result handler and
the fault handler. The creationcomplete identifies the function it
needs to execute(loadData) and the click event on your button
identifies the function it needs to execute(reload). From there you
should be able to just add the url if it hasn't been already and
fire test.send().



Then test.send() will either hit the resultHandler or the
faultHandler.



I hope this helps.

Avatar

Former Community Member
Hi



I dont know how to pass a XML generated by a Java method to
Flex, already Flex is compilating it like a String when I use the
remote object.



Does anyone know what to do?



Thanks

Avatar

Level 2
check the resultFormat property of the HTTPService instance
and you might have to set to e4x to have it treat the response as
XML.




http://livedocs.adobe.com/flex/3/langref/mx/rpc/http/HTTPService.html#resultFormat



ATTA