Sending javascript objects to Harbour hashes

mod_harbour is an Apache module that allows to run PRGs directly on the web !!!
Post Reply
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Sending javascript objects to Harbour hashes

Post by Antonio Linares »

live demo:
https://www.modharbour.org/modharbour_s ... to_prg.prg

source code:
https://github.com/FiveTechSoft/mod_har ... to_prg.prg

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

live demo:
https://www.modharbour.org/modharbour_s ... _to_js.prg

source code:
https://github.com/FiveTechSoft/mod_har ... _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
Taavi
Posts: 77
Joined: Mon Nov 21, 2005 10:29 am

Re: Sending javascript objects to Harbour hashes

Post by Taavi »

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

Taavi.
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Sending javascript objects to Harbour hashes

Post by Antonio Linares »

Taavi,

Code: Select all

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

Re: Sending javascript objects to Harbour hashes

Post by Taavi »

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
User avatar
Antonio Linares
Site Admin
Posts: 37481
Joined: Thu Oct 06, 2005 5:47 pm
Location: Spain
Contact:

Re: Sending javascript objects to Harbour hashes

Post by Antonio Linares »

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

Re: Sending javascript objects to Harbour hashes

Post by Taavi »

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.
Post Reply