ruby on rails - Respond with javascript to an HTML request? -


is possible respond html request javascript? mean don't want page refreshed , plus execute javascript code. wonder if possible changing server side?

in action, have selected respond js , html this:

respond_to |format|   format.js   format.html end 

and have .js.erb file that, of course, should rendered when browser requests javascript.

can done? how?

you cannot changing server side code. if you'd javascript executed upon server's response, form need submitted through javascript. because javascript eval response server , run code.

this can trivially added in rails:

<%= form_for @user, remote: true %> 

when submitted, can send javascript. example, alert user added:

/app/views/users/create.js.erb

alert("user <%= j @user.email %> added"); 

Comments

Popular posts from this blog

python - How to create a legend for 3D bar in matplotlib? -

php - Dynamic url re-writing using htaccess -

java - Multi-Label Document Classification -