Timo,

I don't know what the problem is. However, I do it in the following manner
and that works  well:

(i) In $.ajax specify that the datatype is json (dataType: 'json')


(ii) In your controllers file

     import simplejson

and, write

def getValuesFromFile():

[...]

return simplejson.dumps(dict(title = title, names = name))



On Thu, Oct 11, 2012 at 5:22 AM, Timo W <[email protected]>wrote:

> Hey,
>
> I want to call a function that I defined in the Controller from javascript
> via AJAX. When the function returns a string everything is perfect, but
> when it returns
> a dict, I get always this error:
>
> *404 - NOT FOUND
> web2py_error:invalid view (default/getValuesFromFile.html)*
>
> My code looks like this:
>
> jQuery("#tabs").bind("tabsselect", function(e, tab) {
>          url = "{{=URL('default', 'indexToSession')}}";
>          $.ajax({                 //send current index to server
>           type: "POST",
>           url: url,
>           data: { currentTabIndex: tab.index}
>         }).done(function( msg) {
>             alert(msg);      // this works, as indexToSession only returns
> a string
>             url = "{{=URL('default', 'getValuesFromFile')}}";
>             $.ajax({                 //get Data to plot
>               type: "POST",
>               url: url
>             }).done(function( data) {
>                 alert(data['names']; // this doesn't work
>             });
>         });
> });
>
> And my controller looks like this:
>
> def getValuesFromFile():
>
> [...]
>
> return dict(title = title, names = name)
>
> def indexToSession():
>
> session.tabindex = int(request.vars.currentTabIndex)
>
> return session.tabindex
>
>
> I don't get the point why it is not working with dict's. I have tried it
> also with the jQuery- Method $.getJSON( ...) and $.get(...) but nothing
> worked.
>
> Can someone give me a hint, why this is not working.
>
> Would be great!
>
> --
>
>
>
>

-- 



Reply via email to