AJAX - Return Arrays and Structs to your JavaScript with XML: Difference between revisions

From DataFlex Wiki
Jump to navigationJump to search
m
add syntax highlighting
m (add syntax highlighting)
(2 intermediate revisions by 2 users not shown)
Line 27: Line 27:
5) return the memory address. This will return the XML document to the JavaScript<br/>
5) return the memory address. This will return the XML document to the JavaScript<br/>


<source lang="dataflex">
  { Published = True  }
  { Published = True  }
  { Description = ""  }
  { Description = ""  }
Line 44: Line 45:
   Function_Return aXML
   Function_Return aXML
  End_Function  // NameChanges
  End_Function  // NameChanges
 
</source>
 
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


= Parsing the XML in JavaScript =
= Parsing the XML in JavaScript =
Line 83: Line 54:
4) get the values from the XML
4) get the values from the XML


<source lang="js">
  function onNameCasing(oRMI) {
  function onNameCasing(oRMI) {
   // If no errors
   // If no errors
Line 111: Line 83:
   }
   }
  }
  }
</source>


[[Category:Web Programming]]
[[Category:Web Programming]]
[[Category:AJAX]]
[[Category:AJAX]]

Navigation menu