I can do that without web2py functions using xmlhttprequest, but I thougth that web2py have special function.
8 авг. 2018 г. 21:19 пользователь "Val K" <[email protected]> написал: It is impossible to return ajax-response from your handler directly without the use of async/await, supported by only modern browsers. The traditional way is to register a callback that will do all the work On Wednesday, August 8, 2018 at 7:04:17 PM UTC+3, Константин Комков wrote: > > I want make very simple thing. When user load page fist time variable x > must be 0. After ajax action variable x must be equal 1. And important > moment, that variable x must be returned in JavaScript function. > > среда, 8 августа 2018 г., 18:03:23 UTC+3 пользователь Anthony написал: >> >> On Saturday, August 4, 2018 at 6:03:59 AM UTC-4, Константин Комков wrote: >>> >>> Hello! >>> >>> Can you take advice, how can I understan than answer from server was >>> received in JS? >>> Controller: >>> def swed(): >>> ajaxAnswer = 0 >>> return dict(ajaxAnswer=ajaxAnswer) >>> def VcodeToDbAndMail(): >>> ajaxAnswer = 1 >>> return dict(ajaxAnswer=ajaxAnswer) >>> JS >>> <script> >>> jQuery('#myform').submit(function() { >>> var x = 0; >>> ajax('{{=URL("VcodeToDbAndMail")}}',['email'], ':eval'); >>> >> >> ':eval' is only relevant if the controller returns a string of Javascript >> code, which your controller actions do not appear to be doing. >> >> >>> $('#code').css('visibility','visible'); >>> x = {{=ajaxAnswer}}; >>> >> >> Note, the value of x in the line above will not be updated dynamically >> based on the value of ajaxAnswer set on the server. Rather, this value is >> set once on the server when the original page containing this Javascript >> code is first served. >> >> You'll need to explain more clearly what you are really trying to do. >> >> Anthony >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to a topic in the Google Groups "web2py-users" group. To unsubscribe from this topic, visit https://groups.google.com/d/topic/web2py/wnyN0bjG2OE/unsubscribe. To unsubscribe from this group and all its topics, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout. -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. For more options, visit https://groups.google.com/d/optout.

