AYUDA EN LÍNEA
 WINDEVWEBDEV Y WINDEV MOBILE

Este contenido se ha traducido automáticamente.  Haga clic aquí  para ver la versión en inglés.
Ayuda / WLanguage / Funciones WLanguage / Funciones específicas de la Web / Funciones varias de WEBDEV
  • Querying a server on the same domain or on a different domain
  • Page that returns JSON data
  • IMPORTANT: JSON validity
  • Security
WINDEV
WindowsLinuxJavaReportes y ConsultasCódigo de Usuario (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Código Navegador
WINDEV Mobile
AndroidWidget Android iPhone/iPadIOS WidgetApple WatchMac Catalyst
Otros
Procedimientos almacenados
Calls the URL of a page on the server that returns data in JSON format (JavaScript Object Notation). The server data is evaluated and returned as an object.
Ejemplo
MesContacts is object dynamic
MesContacts = JSONExecute(FolderWeb() + "FR/Page_Objet.awp?id=12")

// Traitement des données reçues
FOR i = 1 _TO_ Dimension(MesContacts:Liste)
	ListAdd(LISTE_Liste_des_contacts, MesContacts:Liste[i]:Nom + ...
	" " + MesContacts:Liste[i]:Prenom)
END
Sintaxis

Synchronous syntax: the function is blocked until IncomingData is received. Ocultar los detalles

<Result> = JSONExecute(<Page URL>)
<Result>: Dynamic object
Data returned by the server. This result must be assigned to a dynamic object.
<Page URL>: Character string
URL of the page that returns the JSON data. It can be an absolute or relative URL.
  • If the URL does not start with 'http:', it is used directly. Warning: the domain must be in the domain of the current page (or a sub-domain), otherwise the call will fail.
  • If the URL starts with '/', it is considered as an absolute path in the current domain.
  • In all the other cases, the URL is considered as a path relative to the directory of the current page.

Asynchronous syntax: a procedure is executed when IncomingData is received. Ocultar los detalles

JSONExecute(<Page URL> , <Procedure name>)
<Page URL>: Character string
URL of the page that returns the JSON data. It can be an absolute or relative URL.
  • If the URL does not start with 'http:', it is used directly. Warning: the domain must be in the domain of the current page (or a sub-domain), otherwise the call will fail.
  • If the URL starts with '/', it is considered as an absolute path in the current domain.
  • In all the other cases, the URL is considered as a 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 <Procédure navigateur> (<Résultat JSON de l'appel>)
The parameter passed to this procedure is a dynamic object that contains the JSON data. It must be indicated in the declaration of the procedure.
Observaciones

Querying a server on the same domain or on a different domain

In most cases, the server is located on the domain that hosts the site. In this case, no specific operation is required.
When querying a server on another domain:
  • the server must implement the CORS protocol,
  • the curernt site must be allowed to contact the server.
For more details, see https://www.w3.org/wiki/CORS about the CORS protocol (Cross-Origin Resource Sharing).

Page that returns JSON data

The page that returns the JSON data can be an Active WEBDEV Page, a PHP page or another type of page.
If it is a WEBDEV page, it can be an Active WEBDEV Page or a PHP page. This page must return the JSON data with StringDisplay. Furthermore, StringToUTF8 must also be used to get a valid format.
For example, the following code creates 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.
sObjet is string = [
{id: 12,
Liste:  [
	{Nom: "smith", Prenom: "john"},
	{Nom: "dupond", Prenom: "marie"},
	{Nom: "martin", Prenom: "lauré"}]
}
]
StringDisplay(StringToUTF8(sObjet))

IMPORTANT: JSON validity

The validity of the JSON data received from the server is not checked. Make sure that the called page is a trusted page to prevent JavaScript injection attacks in the current page.

Security

To protect data, you can use a secure page (https URL).
Componente: WDJS.DLL
Versión mínima requerida
  • Versión 14
Comentarios
Haga clic en [Agregar] para publicar un comentario

Última modificación: 21/09/2024

Señalar un error o enviar una sugerencia | Ayuda local