Shoot, so now I have to have different behavior based on the web2py 
version.  If I fix this code so it runs properly, it will quit working on 
my production servers unless I upgrade them to 2.9.12 or later.

To make it compatible with both versions I'd need to use 
json.dumps(list_of_dictionaries) instead of 
response.json(list_of_dictionaries), right?  But then that is the wrong 
behavior in the long run, right?

-Jim

On Monday, April 20, 2015 at 1:45:53 PM UTC-5, Niphlod wrote:
>
> there you are! response.json now sets content-type = application/json as 
> it's supposed to be (if no specific content-type header is specified)
> Previous versions relied on the user setting the right content-type, but 
> we noticed that nobody was properly setting it.
>
> <tl;dr> web2py fixed a "behavioural bug", setting the proper content-type, 
> and your view worked around a "behavioural bug" (you didn't set the 
> content-type) that wasn't supposed to be there in the first place. Strip 
> $.parseJSON: it's useless now because response.json doesn't return a string 
> that can be parsed as a json object, but the json object itself.
>
> On Monday, April 20, 2015 at 8:41:25 PM UTC+2, Jim S wrote:
>>
>> 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
>>
>>

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