FiveTech Support Forums

FiveWin / Harbour / xBase community
Board index mod_harbour Sending javascript objects to Harbour hashes
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Sending javascript objects to Harbour hashes
Posted: Sat May 02, 2020 09:20 AM
live demo:
https://www.modharbour.org/modharbour_samples/js_to_prg.prg

source code:
https://github.com/FiveTechSoft/mod_harbour/blob/master/samples/js_to_prg.prg

We also provide the demo to convert Harbour hashes into javascript objects:

live demo:
https://www.modharbour.org/modharbour_samples/prg_to_js.prg

source code:
https://github.com/FiveTechSoft/mod_harbour/blob/master/samples/prg_to_js.prg

This way you clear understand how to send values from Harbour to javascript and from javascript to Harbour

Harbour for the web power! :-)
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 97
Joined: Mon Nov 21, 2005 10:29 AM
Re: Sending javascript objects to Harbour hashes
Posted: Sat May 02, 2020 11:15 AM

Hello Antonio,
what is the way to access localStorage.getItem() /and other javascript objects/ directly from mod_harbour code?

Taavi.

Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sending javascript objects to Harbour hashes
Posted: Sat May 02, 2020 01:26 PM
Taavi,

Code (fw): Select all Collapse
function Main()

   LocalStorageSetItem( "Name", "Taavi" ) 

   ShowLocalStorageItem( "Name" )

return nil  

function LocalStorageSetItem( cKey, cValue )

return AP_RPuts( "<script>localStorage.setItem( '" + cKey + "','" + cValue + "')</script>" )

function ShowLocalStorageItem( cKey )

return AP_RPuts( "<script>alert( localStorage.getItem( '" + cKey + "') )</script>" )
regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 97
Joined: Mon Nov 21, 2005 10:29 AM
Re: Sending javascript objects to Harbour hashes
Posted: Sun May 03, 2020 02:36 PM

Is it possible to get value instead of showing it with js alert?

Something like this?

function Main()
local cname

   LocalStorageSetItem( &quot;Name&quot;, &quot;Taavi&quot; )

   cname:=LocalStorageGetItem( &quot;Name&quot; )

return nil
Posts: 44162
Joined: Thu Oct 06, 2005 05:47 PM
Re: Sending javascript objects to Harbour hashes
Posted: Sun May 03, 2020 03:45 PM

Dear Taavi,

The PRG runs on the server, where there is no "localStorage".

The "locaStorage" lives in the client side, where there are no PRGs, and we only have HTML and javascript.

When you use LocalStorageGetItem( "Name" ), we are creating a javascript script that will run on the client side.

So there is no way to assign its result to a PRG variable as by that time mod_harbour has ended its work and the action is at the client side.

What you can do is to send the value in "localStorage" back to the server, exactly using the technique that I have posted in this thread.

regards, saludos

Antonio Linares
www.fivetechsoft.com
Posts: 97
Joined: Mon Nov 21, 2005 10:29 AM
Re: Sending javascript objects to Harbour hashes
Posted: Sun May 03, 2020 06:16 PM

Thanks. Antonio.

...just wanted to be sure there is no other way...

Seems we've got our first simple mod_harbour project up and running :-). Keep learning here...

Taavi.

Continue the discussion