Talk:AJAX - Return Arrays and Structs to your JavaScript with XML

From DataFlex Wiki
Jump to navigationJump to search

From Akennard:

I just wanted to ask 'why' this works ....



 Get paXml of hoXml to aXml
 Send Destroy of hoRoot
 Send Destroy of hoXML	
 Function_Return aXML

End_Function

Is it because VDF does not ACTUALLY destroy and objects untill it gets to end_function ? because returning a handle to something you have just destroyed doesn't look quite right ? ie you are returning a handle to nothing or something that might still exist at that point ? VDF has a special XmlHandle return type for returning a hoXML object and the tidying up after itself Is there a reason why this has not been used in this case ? eg would this work for AJAX ?

{ Published = True } { Description = "" }

Function NameCasing String sName Returns XMLHandle

 Handle hoRoot hoXML hoEvent
 Address aXml
 // create xml document
 Get Create U_cXMLDOMDocument                            to hoXML
 Set pbValidateOnParse of hoXML                          to False
 Get CreateDocumentElement of hoXML "response"          to hoRoot
 Send AddElement of hoRoot "lowercase" (lowercase(sName))
 Send AddElement of hoRoot "uppercase" (Uppercase(sName))	
 Send AddElement of hoRoot "propercase" (Uppercase(Left(sName,1))+lowercase(Right(sName,(length(sName)-1))))	
 Function_Return hoXML  // runtime will transfer and then destroy this object because of XMLHandle return type

End_Function // NameChanges

I believe using JSon is a much better match.

We have been using JSON to move VDF Structs to Javascript. This is I believe a much nicer and simpler way (and definately faster). We did one test of all customers, with all orders, with all orderlines, from VDF to ASP. On this particular laptop using VDF took 40 seconds, sending the same data using JSon it took 1.2 seconds...

Anyway, no time now to update an article, but just wanted to point this out.