问题描述
我有一个包含散列的网址,例如
在浏览器中加载上述url时,我需要根据哈希中的值调用serverside javascript。 / p>
我已经找到了一些像这样回顾哈希客户端的方法
var key = getHashUrlVars()[key];
所以我在onclientload事件中的客户端脚本中提供了可用的键。
因此,在同一个onClientLoad事件中,我现在需要调用我的服务器端JavaScript方法,所以我尝试了以下内容:
'#{javascript:doStuff(key)}'
'#{javascript:doStuff('+ key +')}'
......以及其他一些方法。但我无法实现它。
也许有一个我可以用来代替的XSP命令?
任何想法如何解决这个问题?
您可以在CSJS中执行XSP.partialRefreshPost并使用参数发送你的数据到服务器:
pre $ var p = {key:getHashUrlVars()[key]}
XSP.partialRefreshPost('#{id:_element_to_refresh_}',{params:p});
要访问SSJS中的参数,请尝试以下操作:
doStuff(param.key)
您可以使用空的div元素作为目标执行SSJS代码。或者您可以使用executeOnServer - 方法:
希望这会有所帮助
Sven
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?
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
这篇关于我如何使用JavaScript的参数调用SSJS方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!