PC SOFT

ONLINE HELP
FOR WINDEV, WEBDEV AND WINDEV MOBILE

Home | Sign in | English US
  • Interrogating a server from the same domain or from a different domain
  • Page returning the data in JSON format
  • IMPORTANT: Validity of JSON
  • Security
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadApple WatchUniversal Windows 10 AppWindows Mobile
Others
Stored procedures
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.
Example
MyContacts is dynamic object
MyContacts = JSONExecute(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 (with quotes)
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.
Versions 22 and later

Asynchronous syntax: a procedure is run when data is received Hide the details

JSONExecute(<Page URL> , <Procedure Name>)
<Page URL>: Character string (with quotes)
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 (with or without quotes)
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.
New in version 22

Asynchronous syntax: a procedure is run when data is received Hide the details

JSONExecute(<Page URL> , <Procedure Name>)
<Page URL>: Character string (with quotes)
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 (with or without quotes)
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.

Asynchronous syntax: a procedure is run when data is received Hide the details

JSONExecute(<Page URL> , <Procedure Name>)
<Page URL>: Character string (with quotes)
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 (with or without quotes)
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.
See http://www.w3.org/TR/cors/ for more details about the CORS protocol (Cross-Origin Resource Sharing).

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 the transmitted data, you have the ability to use a secure page (https).
Components
WEBDEV - Browser code WDJS.DLL
Minimum required version
  • Version 14
Comments
Click [Add] to post a comment