Sunday, 15 April 2012

java - How to access Struts 2 variables in jQuery -


I'm trying to access a Stash 2 property through jQuery.

My normal. The Js file looks like this:

  $ (document) .ready (function () {warning ("& lt; s: asset value = 'myVariable' / & gt;");} );   

When I load my view, it returns the full string warning instead of resolving the Straps 2 variables. I'm guessing that I have some random moves ... any help would be appreciated Thanks!

You should put the script on JSP

  & lt; Top & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {warning (& lt; s: asset value = "myVariable" />);}); & Lt; / Script & gt; & Lt; / Head & gt;   

You can not use the string or other JSP tags inside the js files. It does not compile by the server However, you can use that function in JSP which will delete those scripts It's called passing the parameter.

  & lt; Head & gt; & Lt; Script type = "text / javascript" src = "& lt; s: url value = '/ js / common.js' / & gt; & Gt; & Lt; / Script & gt; & Lt; Script type = "text / javascript" & gt; $ (Document) .ready (function () {alertMyVariable (& lt; s: property value = "myVariable" />);}); & Lt; / Script & gt; & Lt; / Head & gt;   

In JS:

  function alert MyVariable {warning (myVariable); }    

No comments:

Post a Comment