开发者

Return a JavaScript's confirmbox response to a ruby program

开发者 https://www.devze.com 2023-01-21 20:12 出处:网络
Sorry if it looks stupid q开发者_开发知识库uestion but is it possible to return the response from a JavaScript confirmbox or messagebox to a ruby program as a value?

Sorry if it looks stupid q开发者_开发知识库uestion but is it possible to return the response from a JavaScript confirmbox or messagebox to a ruby program as a value?

I click on confirmbox's "yes" button, this response is stored in a variable, and then this variable is returned to ruby?


Sure, it´s easy. Just send an XHR back to the server. If your are using jQuery you could do something like this:

$.getJSON('/path/to/check', {client_data: stuff}, function(response) {
     //e.g. server returns
     if (response.ask && window.confirm("Sure?") || !response.ask) { 
         sendMyStuffToServer();
     }
})

An XHR request (aka AJAX) is basically the same as a normal one except that it's performed in background (which looks like what you are looking for).

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号