How to use google app engine with ajax (json)?
Now I have this but I got this error:
raise ValueError("No JSON object could be decoded&q
Your JavaScript is not sending JSON data to App Engine (test=hey&y=99 is a urlencoded string). Your App Engine page is not returning JSON data (Hello, webapp World! will just be received as a naked string).
as long as I know self.request.body wouldn't return anything. There's no argument named 'body' in your query-string, but I might be wrong. So, if it returns something, this something is a STRING. So simplejson.dumps() cannot turn it into a valid JSON.
If you need a 'list' of all arguments you have sent to the server, use self.request.arguments()
self.response.out.write('Hello, webapp World!') do not send a valid JSON back to client. It sends a string with "application/json" header instead of "plain/text". Try to create a python dictionary. For example:
my_response = {'ajax_resp':'Hello, webapp World!'}
json = json.dumps(my_resposne)
and then
self.response.headers.add_header('content-type', 'application/json', charset='utf-8')
self.response.out.write(json)
On the client side I would suggest you to use console.log() (debugging tool) for testing your responses.
you can just try:
$.ajax({
type: 'GET',
url: '/AJAX', // or your absolute-path
data : name=totty&age=20,
dataType : 'json',
success : function(resp)
{
console.info("Ajax Response is there.....");
console.log(resp);
}
});