On Tuesday, September 4, 2018 at 6:23:03 AM UTC-7, Константин Комков wrote:
>
> Hello, can you take advice can I send variables in web2py function - ajax 
> or I need to use jquery function.
> Can somebody show example how to send variables with jQuery.ajax and get 
> answer from server (controller and js in view).
> For example we have a = 2 and b = 3. I want to get from server a+b.
>
>
I have used (in example.html)

<DIV id="my_target">
</DIV>

[...]

<button onclick='ajax("myfunction.html", ["myarg1","myarg2","myarg3" ], 
"my_target", type="submit", name="myvalue1". value={{request.vars.myarg1"}}>



(I also have a $(document).ready(...) to set some visibilities to "hidden")

In the controller, I have stuff like

def myfunction():
    if request.vars.arg1:
        myvar = request.vars.arg1
    else:
        if shouldbeerror:
             raise HTTP(501, 'no data')
        else:
             myvar = usethisdefault()
    return dict(output=str(myvar))


that is, the controller accesses the variables just like it would any other 
request.

/dps


-- 
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