Hi Yannik,

Probably something like:

# the view:
{{extend 'layout.html'}}

<a href="#"
   onclick="$.getJSON('{{=URL(r=request,f='my_json',args=['a test
string'])}}',
                    function(data){ alert(data) });">
    Please click here.
</a>

# the controller:
def my_json():
    try:
        argument=request.args[0]
        import gluon.contrib.simplejson as simple_json
        return simple_json.dumps(argument)
    except IndexError:
        return dict()



On Mar 27, 4:33 am, Yannick <ytchatch...@gmail.com> wrote:
> Hello Mate,
> This is probably a really simple issue... I want to send data to an
> action  from the views using JSON and here is a sample of my code
>
> In the view:
> ***********************************************
> <script>
> $.getJSON('/AppName/default/ActionName', 'DATA2SEND2Action' , function
> (datafromServer){ ........ });
> </script>
> ***********************************************
>
> In the Controller (Here I'm trying to retrieve data sent from view
> using 'request.args' )
> **********************************************
> def actionName:
>      argument = request.args[0]
>      ......
>      ......
>      ......
>      return argument
> **********************************************
>
> I got an error message complaining about the index... Here is the
> error:
>
> File "/opt/web2py/applications/BU/controllers/default.py", line 99, in
> actionName
> argument = request.args[0]
> IndexError: list index out of range
>
> PS:
> I'm using Firebug to debug my JavaScript code and here is the request
> link I got:
> GEThttp://127.0.0.1:8000/AppName/default/actionName?DATA2SEND2Action
>
> DO you pleaz have any idea ? , I'm pretty sure I'm doing something not
> really correct somewhere...
>
> Do you know a better way to communicate from Views to Action using
> JSON with Web2Py?
>
> Please help !
>
> Thanks for your attention,
> Regards,
> Yannick P.
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"web2py Web Framework" group.
To post to this group, send email to web2py@googlegroups.com
To unsubscribe from this group, send email to 
web2py+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/web2py?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to