http://www.web2py.com/books/default/chapter/29/11/jquery-and-ajax#The-ajax-function



Note the diference between :eval and the 'target' id alternative
If you use eval than you have to return not locals() but a string with
javascript to be evaluated like for example jQuery('#target').html('100');

from the docs...

{{extend 'layout.html'}}<form>
   <input name="name" onkeyup="ajax('{{=URL('default', 'echo')}}',
['name'], 'target')" /></form><div id="target"></div>


{{extend 'layout.html'}}<form>
   <input name="name" onkeyup="ajax('{{=URL('default', 'echo')}}',
['name'], ':eval')" /></form><div id="target"></div>




Em qua, 17 de abr de 2019 às 12:18, mostwanted <[email protected]>
escreveu:

> I am trying to do something that is supposed to be relatively simple, i
> want to submit a value through a form to a controller for calculations
> using ajax so that the page doesn't refresh but i am not getting any
> results back in my view, i changed the way of doing that using ajax just
> a-little bit, here is an example below: Its not working, I just wanna
> submit a value from a view to a function without the view refreshing!
>
> *VIEW:*
> {{extend 'layout.html'}}
>
> <div>The answer: {{=answer}}</div>
>
> <form id="myform">
> <input name="name"/> <input type="submit" />
> </form>
>
> <script>
> $('document').ready(function(){
> $('#myform').submit(function() {
> ajax("{{=URL('index')}}",['name'], ':eval');
> return false;
> });
> });
> </script>
>
> *CONTROLLER:*
> def index():
>     answer=0
>     info=request.vars.name
>     if info is None:
>         info=0
>     if info:
>         info=int(info)
>         num1=200
>         answer=info-num1
>     return locals()
>
> Help!!!
>
> Mostwanted
>
> --
> 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.
>

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

Reply via email to