0

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?

1 Answer 1

1

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
  });
Sign up to request clarification or add additional context in comments.

2 Comments

or can I just access the filledInPixels variable in my controller?
Only if you pass it as a parameter in your ajax call: $.get( "/controller/action.json", { filledInPixels: filledInPixels } );.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.