简体   繁体   English

如何将JavaScript变量传递给gsp标签

[英]How to pass javascript variable to gsp tag

<script>
   var numx = 5000;
   alert('${myCustomTagLib(number:"numx")}')
</script>

How to pass javascript varable "numx" to gsp tag? 如何将javascript变量“ numx”传递给gsp标签?

You clearly needs to understand, when GSP is executed and when JavaScript is executed. 您显然需要了解何时执行GSP和何时执行JavaScript。

Execution of GSP happens in the server. GSP的执行在服务器中进行。 At this point, there is no JavaScript variable to assign. 此时,没有JavaScript变量要分配。 So your "numx" in always null, when "myCustomTagLib" is called. 因此,当“ myCustomTagLib”被调用时,您的“ numx”始终为空。

You cannot do like that way but you can do it with ajax 您不能那样做,但是可以使用ajax

$.ajax({
   type: "POST",
   url: "/someController",
   data: { number: numx } // here  send the data to your controller and process it
})
.done(function( msg ) {
    // display the processed data here
    alert(  msg );
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM