Pass Button Value using javascript and make it usable in xwiki macro

一个人想着一个人 提交于 2019-12-13 03:59:21

问题


So I have 2 buttons and each button click is supposed to call 2 different functions. I figured I can use Javascript to get the values but how do I get the value to be usable in a macro? What I have tried is this

<script type="text/javascript">
     function getVal(value){
         #set $value=value
         alert(value)
        }
</script>

Obviously this does not work. Without the #set $value=value code, I see an alert every time I click on something.


回答1:


You're trying to mix two completely different languages. One is executed on the server, one on the client, and there's no direct connection between them. Once the HTML reaches the browser, Velocity has long stopped executing, and you can't get back to it from JavaScript.

Well, not directly.

When you have to go back from JavaScript to Velocity, you usually send an XHR with some piece of information, back to the server. The document where you send the request will detect what kind of request you're sending (using a request parameter), will perform the requested action, and will generate a response to be sent back to the JavaScript side.

You can find an example in the blog categories management code.



来源:https://stackoverflow.com/questions/18328871/pass-button-value-using-javascript-and-make-it-usable-in-xwiki-macro

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!