Thank you, now I use it, becouse I haven't form only variables (delFo,
delFac, delDir, delPr) in JavaScript:
view:
data = {fo : delFo, fac : delFac, direction : delDir, pr : delPr};
jQuery.ajax({
type: "POST",
url: "deleteCompetition",
data: 'data='+JSON.stringify(data),
cache: false,
success: function(response) {
alert("Deleted");
}
});
controller:
def deleteCompetition():
a = json.loads(request.vars.data)
i = 0
for b in session.prog_list:
if (b['fo']==a['fo'].encode('utf-8')) &
(b['fac']==a['fac'].encode('utf-8')) &
(b['dir']==a['direction'].encode('utf-8')) &
(b['prog']==a['pr'].encode('utf-8')):
del session.prog_list[i]
break
среда, 5 сентября 2018 г., 2:52:19 UTC+3 пользователь Dave S написал:
>
>
>
> 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 [email protected].
For more options, visit https://groups.google.com/d/optout.