简体   繁体   中英

How do you access a JavaScript variable inside a Rails escape_javascript line?

Say I'm inside a JavaScript function, I'd like access to data within the Rails line like this:

var DATA_USED
html = "<%= escape_javascript(render :partial => 'change_date_range', :locals => {:end_date_string => DATA_USED }) %>";

You really should use AJAX (I recommend jQuery ) for this. You'll want to have JS send a request back to your Rails server with the JavaScript variable as a param in the request.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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