开发者

Return a JavaScript's confirmbox response to a ruby program

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜