How do I call an SSJS method with parameters from

2019-01-29 06:49发布

I have a url containing a hash e.g http://www.acme.com/home.xsp#key=1234

When the url above loads in the browser I need to call a serverside javascript based on the value in the hash.

I have found a few ways of retriving the hash client side like this

var key = getHashUrlVars()["key"];

so I have the key available in my client side script in the onclientload event.

So in the same onClientLoad event I now need to call my server side javascript method so I have tried the following

'#{javascript:doStuff(key)}' 
'#{javascript:doStuff(' + key + ')}' 

..and a few other ways. but I can't get it to work.

maybe there is an XSP command I can use instead? any ideas how to solve this?

1条回答
Lonely孤独者°
2楼-- · 2019-01-29 07:30

You could do a XSP.partialRefreshPost in CSJS and use parameters to send your data to the server:

var p = { "key": getHashUrlVars()["key"] }
XSP.partialRefreshPost( '#{id:_element_to_refresh_}', {params: p} );

To access the parameters in SSJS just try this:

doStuff( param.key )

You could use an empty div-element as a target execute the SSJS code. Or you can use the executeOnServer - method: http://xpages.info/XPagesHome.nsf/Entry.xsp?documentId=88065536729EA065852578CB0066ADEC

Hope this helps

Sven

查看更多
登录 后发表回答