Help / WLanguage / WLanguage functions / Web-specific functions / Ajax functions
  • Usage example of the AJAXExecute function
AJAXExecute (Example)
Usage example of the AJAXExecute function
This example is used to return a complex structure in a procedure called in Ajax to exploit the result in a browser procedure.
// Call to an Ajax procedure that returns a Json string
sZone is string
sZone = AJAXExecute(ajaxStraightCall, ServerProcReturnJsonData, "Eiffel Towel")
// Transforms the received JSon buffer into object
EXTERN JSON // Informs the compiler not to trigger any error on JSON.xxxx (JavaScript object)
stZone is object dynamic = JSON.parse(sZone)
// Analyze the result
IF NOT stZone.bFound THEN
Info("Zone not found", stZone.sErrorMessage)
// The points to display
APosition is geoPosition
FOR n = 1 _TO_ stZone.aaCoordinates..Count
APosition.Latitude = stZone.aaCoordinates[n].rLatitude
APosition.Longitude = stZone.aaCoordinates[n].rLongitude
MapAddMarker(MAP_Plan, APosition)
// The center of the map
APosition.Latitude = stZone.stCenter.rLatitude
APosition.Longitude = stZone.stCenter.rLongitude
MapDisplayPosition(MAP_Plan, APosition)
// The zoom
MAP_Plan..Zoom = stZone.nZoom
ToastDisplay("Zone " + stZone.sZoneName + " displayed")
// ------------------------------------
// --Server procedure ServerProcReturnJsonData
// ------------------------------------
PROCEDURE ServerProcReturnJsonData(...
sParameterZoneName is string <useful="Name of the zone whose coordinates are requested">)
// Structure to store a point
st_MapPoint is Structure
rLatitude is real
rLongitude is real
// Structure to return to the page
st_DataForBrowserCode is Structure
sZoneName is string
// To manage the error cases
bFound is boolean
sErrorMessage is string
// Center of the map and zoom
stCenter is st_MapPoint
nZoom is int
// Other points
aaCoordinates is array of st_MapPoint
// Variable to store what must be sent to the page
stResForPage is st_DataForBrowserCode
// Variable for the coordinates of a point
stAPoint is st_MapPoint
// Name of the zone
stResForPage.sZoneName = sParameterZoneName
// The zone could be found in a database:
// IF not HReadSeekFirst(Zone, ZoneName, sParameterZoneName) THEN
// stResForPage.bFound = False
// stResForPage.sErrorMessage = "Zone not found"
// stResForPage.bFound = True
// // then, read the informations of the zone
// // etc.
// END
// Return hard-coded data
stResForPage.bFound = True
// Add a point
stPoint.rLatitude = 48.860501
stAPoint.rLongitude = 2.295683
ArrayAdd(stResForPage.aaCoordinates, stAPoint)
// Add another point
stPoint.rLatitude = 48.859352
stAPoint.rLongitude = 2.297374
ArrayAdd(stResForPage.aaCoordinates, stAPoint)
// Add another point
stPoint.rLatitude = 48.856397
stAPoint.rLongitude = 2.293040
ArrayAdd(stResForPage.aaCoordinates, stAPoint)
// Add another point
stPoint.rLatitude = 48.857478
stAPoint.rLongitude = 2.291176
ArrayAdd(stResForPage.aaCoordinates, stAPoint)
// etc...
// Center of the map
stResForPage.stCenter.rLatitude = 48.858288
stResForPage.stCenter.rLongitude = 2.294453
// Zoom of the map
stResForPage.nZoom = 15
// Serializes the data to transmit to the page in JSON
bufJson is Buffer
Serialize(stResForPage, bufJson, psdJSON)
RESULT bufJson
Minimum version required
  • Version 10
Click [Add] to post a comment

Last update: 05/26/2022

Send a report | Local help