Reboot Reboot - 2 years ago 80
jQuery Question

Jquery running code before pressing the button

I am not sure if this is the correct way to do this or not. In my Rails application I have something like this.

<input id='foo' type="submit" value=" - Test - "/>

$(document).ready(function () {

$("#foo").click(function() {
alert("Clicked Test button");
'<% j @customer.do_something('Test', 'test') %>'; <-- This line is running without user pressing the button.


Is it possible to call some method on
object when the button is pressed? Or do I need to do this via ajax? Currently
is executed even when I haven't pressed the button.

What is the correct way of calling Model methods once the button has been pressed?

Answer Source

The ERB (ie. the stuff in <% %>s) will be run on the server BEFORE the content is sent to the browser.

If you want to run it as the result of the click then yes, you will need to use Ajax.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download