|
|
|
|
|
- Interrogating a server from the same domain or from a different domain
- Page returning the data in JSON format
- IMPORTANT: Validity of JSON
- Security
JSONExecute (Function) In french: JSONExécute Calls a server URL that returns data in JSON format (JavaScript Object Notation). The server data is evaluated and returned in object format. MyContacts is dynamic object MyContacts = JSONExécute(FolderWeb() + "US/Page_Object.awp?id=12")  // Process the data received FOR i = 1 _TO_ Dimension(MyContacts:List) ListAdd(LIST_List_of_contacts, MyContacts:List[i]:Name + ... " " + MyContacts:List[i]:FirstName) END
Syntax
Synchronous syntax: the function is locking until data is received Hide the details
<Result> = JSONExecute(<Page URL>)
<Result>: Dynamic object Data returned by the server. This result must be assigned to an object whose type is dynamic object. <Page URL>: Character string URL of the page that returns the data in JSON format. This URL can be a partial URL or a full URL.- If the URL does not start with 'http:', this URL is used directly. Caution: the domain must be found in the domain of the current page (or in a sub-domain), otherwise the call fails.
- If the URL starts with '/', the URL is considered as full path in the current domain.
- In all the other cases, the URL is considered as path relative to the directory of the current page.
Asynchronous syntax: a procedure is run when data is received Hide the details
JSONExecute(<Page URL> , <Procedure name>)
<Page URL>: Character string URL of the page that returns the data in JSON format. This URL can be a partial URL or a full URL. - If the URL does not start with 'http:', this URL is used directly. Caution: the domain must be found in the domain of the current page (or in a sub-domain), otherwise the call fails.
- If the URL starts with '/', the URL is considered as full path in the current domain.
- In all the other cases, the URL is considered as path relative to the directory of the current page.
<Procedure name>: Character string Name of the browser procedure (global or local procedure) that performs the process of the JSON data. This procedure has the following format:PROCEDURE <Browser procedure> (<JSON result of call>) The parameter passed to this procedure is a dynamic object, containing the JSON data. It must be indicated in the declaration of the procedure. Remarks Interrogating a server from the same domain or from a different domain In most cases, the server is found on the domain that is hosting the site. In this case, no specific operation is required. When interrogating a server from another domain: - the server must implement the CORS protocol,
- the curernt site must be allowed to contact the server.
Page returning the data in JSON format The page that returns the data in JSON format can be an AWP page, a PHP page or another type of page. If this page is a WEBDEV page, this page can be in AWP format or in PHP format. This page must return the data in JSON format with StringDisplay. Furthermore, StringToUTF8 must also be used to get a valid format. For example, the following code is used to create the string that will be returned. This string contains the code used to define an object and an array. The code used is Javascript code. sObject is string = [ {id: 12, List: Â [ {Name: "smith", FirstName: "john"}, {Name: "doe", FirstName: "mary"}, {Name: "martin", FirstName: "laura"}] } ] StringDisplay(StringToUTF8(sObject))
IMPORTANT: Validity of JSON No check is performed regarding the validity of JSON received from the server. Make sure that the page called in a trusted page to avoid having a JavaScript injection in the current page. Security To increase the security of transmitted data, you have the ability to use a secure page (https).
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|