Date:  08/07/2018 02:13:35 AM Msg ID:  004960
From:  FoxWeb Support Thread:  004957
Subject:  Re: Access foxweb\'s JSON sting in Javascript
Jeff's response describes the more common (and probably better method) of retrieving data through separate ajax calls. If you would like to return the data with your HTML and javascript code, you can dynamically generate the javascript as follows:
 

<%

SELECT * FROM SON5200 INTO CURSOR crScharge ORDER BY Servcode

IF _TALLY > 0

    SchargeJSON = fwJSON.WriteCursor()

ENDIF

%> 

 

<script type="text/javascript>

    var scharge = JSON.parse('<%=SchargeJSON%>');

    ...JS code that uses the data in the scharge variable

</script> 

 
Note the the above code is just an example to illustrate this specific technique. You should probably make sure to not create variables in the global scope and in general use modern JS practices.
FoxWeb Support Team
support@foxweb.com email
Sent by Olatunji Beckley on 08/05/2018 02:42:30 PM:
The foxweb script below already stores the json string to the variable SchargeJSON.
 
(Sample Foxweb  Script):
 
SELECT * FROM SON5200 INTO CURSOR crScharge ORDER BY Servcode
IF _TALLY > 0
    SchargeJSON = fwJSON.WriteCursor()
ENDIF
 
In the same foxweb script, i have a form with a select input type with the onchange event attribute that calls a javascript function "servLookup1()". See the script below.
 
<select id="servcode1" name="servcode1" onchange="servLookup1()"> 
 
The problem is that i need to reference the foxweb variable "SchargeJSON" in the javascript.
 
Sent by Jeff Grippe on 08/01/2018 08:46:16 PM:
Hello,
 
I think you need to use Response.Write(fwJSON.WriteCursor()) so that the FWX will return json instead of a page. Then all you have to do is to write an ajax/ http request.
 
 
users={}
$http.get('\getusers.fwx').then(function(resp){
users =resp.data;
});
 
Sent by Olatunji Beckley on 07/27/2018 04:02:09 PM:
Hi All,
 
This is really not a foxweb issue, but need someone to help or suggest a solution.
 
I would like to access a json string generated with fwJSON.WriteCursor() as a JSON object in javascript function.  
 
E.g. (Sample Foxweb  Script):
 
SELECT * FROM SON5200 INTO CURSOR crScharge ORDER BY Servcode
IF _TALLY > 0
    SchargeJSON = fwJSON.WriteCursor()
ENDIF
 
Is there a way to reference the SchargeJSON variable/object in a javascript function?
 
TIA