Reputation: 6304
I have the following code, using Crockford's json2 to parse the object into json data.
using chrome dev tool the parsed string is "{"query":"asd"}"
.
However on the django server side, I keep getting an exception when I try to decode the post
json data.
Turns out the parsed json string became a key in the dictionary.
The query dict from the POST became this: {u'{"query":"asd"}': [u'']}
, the json data became the key and the value became an empty string.
Is there a way to rectify this? so the result would be normal json data when the server receives it.
// convert object to JSON data
var jsonQuery = JSON.stringify(prod_query);
$.ajax({
type: 'POST',
url: '/company/product/item_search.json/',
data: jsonQuery,
success: //do stuff
}
});
}
});
python view
query = simplejson.loads(request.POST)
Upvotes: 1
Views: 1460
Reputation: 599610
You want to pass request.raw_post_data
to simplejson.loads
.
Upvotes: 3