I'm using python for a light web application based on BaseHTTPServer and CGIHTTPServer.
I have a little issue with an ajax call, which retrieves a dictionary to fill a select widget. Being "list" the select ID this is the javascript code to dynamically fill the options :
$.getJSON("/web/ajax/list.py", function(result) {
$.each(result, function(key, value){
$("#list").append("<option id=" + key + ">" + value + "</option>");
});
});
In the server side file list.py I can't simply dump the dictionary contents using json.dumps but I'm forced to print some empty lines before doing so:
options = {}
options[1] = "option 1"
options[2] = "option 2"
options[3] = "option 3"
# Whitout these two lines it doesn't work!!
print """
"""
import json
print json.dumps(options)
Any ideas why this doesn't work just by dumping the dictionary ?
I'd like to get rid of the extra print.