Max
Max

Reputation: 275

calling a rails controller method with javascript

I got a javascript funktion:

function handlePercentage(filledInPixels) {
  filledInPixels = filledInPixels || 0;
  console.log(filledInPixels + '%');
  if (filledInPixels > 80) {
    canvas.parentNode.removeChild(canvas);
  }
}

Now I want to access a rails controller to check a random string when filledInPixels > 80

How can I do that without reloading the page?

Upvotes: 0

Views: 1609

Answers (1)

Uzbekjon
Uzbekjon

Reputation: 11813

Just make a GET or POST AJAX call to your Rails resource.

If you are using jQuery:

$.get( "/controller/action.json", { your: "params", another: "value" } )
  .done(function( data ) {
    // Access your data here
  });

Upvotes: 1

Related Questions