Hi all,
I'm having some issues with json, http post and django.
The issue is that the JSONObject.toString() or HTTP POST request
builder contaminates the json string with newlines causing malformed
javascript to be sent and a ValueError thrown in Djangos simplejson
parser on the other side.
Here's how I build the request:
if(this.key != null)
{
JSONObject form = new JSONObject();
form.put("key", new JSONString(this.key));
form.put("content", new
JSONString(getDocumentContent()));
form.put("title", new JSONString(getDocumentTitle()));
try {
requestBuilder.sendRequest("json="+form.toString(), new JSONhandler
());
} catch (RequestException e) {
Window.alert(e.getMessage());
e.printStackTrace();
}
}
Here's how I process the request in Django:
def save_page(request):
if(request.method == 'GET'):
pass
else:
json = request.POST['json']
decoder = simplejson.JSONDecoder()
props = decoder.decode(json)
try:
page_id = 1
page_alias = "Start"
m_page = Page.objects.get(pk=page_id)
except Page.DoesNotExist:
m_page = Page(alias=page_alias, rev=0)
m_page.save()
title = props['title']
content = props['content']
title = "test"
content=json
revision = Revisions(page=m_page, rev=m_page.rev+1,
title=title, content=content)
revision.save()
m_page.rev = m_page.rev + 1
m_page.save()
return render_to_response("it works")
I've determined that the newlines most likely added in the HTTP
request builder, but I haven't been able to debug it.
Has anyone here encountered and solved this problem before?
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Google Web Toolkit" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/Google-Web-Toolkit?hl=en
-~----------~----~----~----~------~----~------~--~---