I am using cherrypy and mongo for a small web application. At some point I want to have a method that returns the object id to a template, ‘_id’ if you may, but parseJSON dismisses it completely. I could rewrite my documents and methods but I was wondering if there is another way around this. In python, I return a dictionary like this:
@cherrypy.expose
@cherrypy.tools.auth(level='mortal')
def add(self, **params):
if cherrypy.request.method == 'POST':
# do stuff
return json.dumps(article)
and in jquery I try to parse it (including the _id variable):
$.ajax({
url: '/org/add',
type: 'POST',
data: data,
dataType:'json',
success: function(data) {
alert(data._id);
error: function() {
alert('error');
}
});
all other variables are returned except _id 🙁 can you help me out on this one?
I’m using python 2.7.5 and jquery 1.8 btw.
I tested with this fiddle http://jsfiddle.net/arhea/GME9S/ and it does not remove underscore properties. It must be your backend code not sending it through. But it should not be the javascript.