This question also comes up a lot, there should be a FAQ and this should be 
in it...

getitemtags

That is your function. You want to have jQuery call your function, and 
parse the json...

instead of trying to mix javascript in your view (which you are lucky if it 
works at all) you should just write javascript, and let javascript handle 
calling the database.

Now there are a few ways to do this. In jQuery you can use an 'ajax()' 
call, though that is very low level, and difficult. You can also use a 
'get()' call, which is easier... There is also a third option, using 
web2py.js and the 'ajax()' function call, which is just for Web2Py. 

http://api.jquery.com/jQuery.get/

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

My recommendation is to try the web2py 'ajax' function, if that doesn't do 
what you want then try the jQuery.get function.

On Monday, October 14, 2013 3:10:42 PM UTC-7, david.waldrop wrote:
>
> All I am trying to pass data from a function to javascript
>
> here is the function in web2py:
>
> def getitemtags(inid):
>     jurisdictions = db(db.jurisdiction.aid == inid).select(
> db.jurisdiction.id, db.jurisdiction.jurisdiction, 
> db.jurisdiction.training, db.jurisdiction.predicted)
>     data = [[row.id, row.jurisdiction, row.training, row.predicted] for 
> row in jurisdictions]
>     return json.dumps(data)
>
> In the view I have the following:
>
>       $().ready(function(){ 
>         console.log('----------- all is loaded  ' + Date());
>         var itemtags = jQuery.parseJSON({{=getitemtags(
> results.update_form.custom.dspval.id)}});
>         console.log(itemtags);
>         // all data should be here now and we can get started
>       });   
>
>
>
> Here is the error output :
>
>
> var itemtags = jQuery.parseJSON([[403, "United States", true, 
> null]])
>
>
>
> Does anyone know how to cleanly pas json data to the client?
>

-- 
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/groups/opt_out.

Reply via email to