I would like to send a list of dictionaries from a web browser to a server running CherryPy. What should the code in CherryPy be to receive it?
JavaScript in Web Browser
var listOfDictionaries = {
"Coordinates":
[
{"x":"892850686394369 ","y":"4c189d55d5a2b4d682647bfcc9e5827112abfe7c"},
{"x":"892850686394430 ","y":"b1c8238337a3e17352718a46ca0a76a7e196adfd"}
]
};
$.post('drawChart', listOfDictionaries,
function (data) {
$("#title").html(data['title']);
});
Data that I am sending via an HTTP POST:
{"Coordinates":[{"x":"892850686394369 ","y":"4c189d55d5a2b4d682647bfcc9e5827112abfe7c"},{"x":"892850686394430 ","y":"b1c8238337a3e17352718a46ca0a76a7e196adfd"}]}
CherryPy method on Web Server
@cherrypy.expose
def drawChart(self, x, y):
cherrypy.response.headers['Content-Type'] = 'application/json'
return json.dumps(dict(title="x: %s" x))