[英]calling a rails controller method with javascript
I got a javascript funktion: 我有一个JavaScript函数:
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
现在我想访问一个Rails控制器以在filledInPixels > 80
时检查随机字符串
How can I do that without reloading the page? 如何在不重新加载页面的情况下做到这一点?
Just make a GET
or POST
AJAX call to your Rails resource. 只需对Rails资源进行GET
或POST
AJAX调用即可。
If you are using jQuery: 如果您使用的是jQuery:
$.get( "/controller/action.json", { your: "params", another: "value" } )
.done(function( data ) {
// Access your data here
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.