Velocity - How to avoid ParseErrorException when using jQuery?

后端 未结 5 391
闹比i
闹比i 2021-02-04 10:23

I\'m trying to add a jQuery post to some JavaScript on a web page. The entire page is built up of several Velocity templates. Everything has been fine until I\'ve tried to add t

5条回答
  •  故里飘歌
    2021-02-04 11:19

    Ok, there appears to be two solutions for this:

    First, with jQuery we can just avoid using the global alias $ and instead use the jQuery object directly:

    jQuery.post(url, myJSONObject, function(result){
    ~~~snip~~~
    

    In my case, the above works great. But I suspect in other scenarios (non-jQuery) this may not be possible. In which case, we can 'hide' our character within a valid Velocity reference like this:

    #set( $D = '$' )
    ${D}
    

    Source: http://velocity.apache.org/engine/devel/user-guide.html#escapinginvalidvtlreferences

    I'd still like to know why the backslash escape didn't work, but the above will at least get me moving again. :)

提交回复
热议问题