Using jQuery and the $.ajax function, I'm returning a json object from my 
controller function using response.json(list_of_dictionaries).

I'm seeing an error in firebug saying:

SyntaxError: JSON.parse: unexpected end of data at ...

Here is the javascript:

    $.ajax({url: "{{=URL('workorder','get_mixer_dropdown', 
user_signature=True)}}",
                data: {site:site}})
        .fail(function() {
            alert('There was a problem retrieving the mixer list.  Please 
contact support.');
        })
        .success(function(msg) {
            options = $.parseJSON(msg);
            $('#workorder_mixer').find('option').remove().end()
            for (i=0;i<options.length;i++) {
                $('#workorder_mixer').append(
                        $('<option />')
                                .text(options[i].text)
                                .val(options[i].id)
                );
            }
            $('#workorder_mixer').attr('disabled',false);
        });

The error is on the $.parseJSON(msg) stating that an invalid JSON object 
was returned.  This error doesn't happen on web2py v2.9.5, but does with 
2.10.4 beta.  Returning from the controller isn't the problem.  The problem 
is when I use response.json(list_of_dictionaries) instead of 
json.dumps(list_of_dictionaries) to convert my list to JSON. 
 response.json(list_of_dictionaries) used to work and now it doesn't.

-Jim

On Monday, April 20, 2015 at 1:10:30 PM UTC-5, Niphlod wrote:
>
> what are you expecting and what do you see instead ?
> returning from controllers is the only supported way.
>
> On Monday, April 20, 2015 at 6:28:14 PM UTC+2, Jim S wrote:
>>
>> I have some controller methods that I call using ajax and they return a 
>> json string using:
>>
>> return response.json(list_of_dictionaries)
>>
>> I just realized today that it isn't working on newer releases.  Based on 
>> the web2py releases that I have, I can see that it works in 2.9.5 but not 
>> 2.9.12.  Also, does not work in 2.10.4 beta from today.  I can get it 
>> working by simply replacing:
>>
>> return response.json(list_of_dictionaries)
>>
>> with
>>
>> return json.dumps(list_of_dictionaries)
>>
>> The problem (at least as I see it) is that backward compatibility is 
>> broken.  Was I using it incorrectly to begin with?  If this is a bug I'd be 
>> happy to open a ticket.  I'd like some confirmation from others whether or 
>> not you see it as a bug or a misuse on my part.
>>
>> -Jim
>>
>

-- 
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 web2py+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to