Sending javascript objects to Harbour hashes

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!

Sending javascript objects to Harbour hashes

Postby Antonio Linares » Sat May 02, 2020 9: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending javascript objects to Harbour hashes

Postby Taavi » 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.
Taavi
 
Posts: 89
Joined: Mon Nov 21, 2005 10:29 am

Re: Sending javascript objects to Harbour hashes

Postby Antonio Linares » Sat May 02, 2020 1:26 pm

Taavi,

Code: Select all  Expand view
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
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending javascript objects to Harbour hashes

Postby Taavi » Sun May 03, 2020 2:36 pm

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

Something like this?

function Main()
local cname

LocalStorageSetItem( "Name", "Taavi" )

cname:=LocalStorageGetItem( "Name" )

return nil
Taavi
 
Posts: 89
Joined: Mon Nov 21, 2005 10:29 am

Re: Sending javascript objects to Harbour hashes

Postby Antonio Linares » Sun May 03, 2020 3: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
User avatar
Antonio Linares
Site Admin
 
Posts: 42097
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain

Re: Sending javascript objects to Harbour hashes

Postby Taavi » Sun May 03, 2020 6: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.
Taavi
 
Posts: 89
Joined: Mon Nov 21, 2005 10:29 am


Return to mod_harbour

Who is online

Users browsing this forum: No registered users and 7 guests