Thank you, I thought that third parametr of ajax function might be only 
'target' or ':eval'.

четверг, 9 августа 2018 г., 17:27:21 UTC+3 пользователь Anthony написал:
>
> Controller:
>
> def VcodeToDbAndMail():
>     return 1
>
> Javascript:
>
> <script>
> let x = 0
>
> function showCode(data) {
>   x = parseInt(data);
>   $('#code').css('visibility', 'visible');
> }
>
> jQuery(function() {
>   jQuery('#myform').submit(function(e) {
>     e.preventDefault();
>     ajax('{{=URL("VcodeToDbAndMail")}}', ['email'], showCode);
>   });
> });
> </script>
>
> The third argument of the ajax() function can be a callback function that 
> takes the response from the server. Above, the server simply returns the 
> value "1", which gets passed to the showCode() callback, which sets the 
> value of x and then makes the "#code" element visible.
>
> Anthony
>
> On Wednesday, August 8, 2018 at 12:04:17 PM UTC-4, Константин Комков 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 the Google Groups 
"web2py-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to