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).
精彩评论