On Nov 13, 2006, at 4:06 PM, Rob Hudson wrote:
>
> I'm building a rating system using AJAX (well, maybe AJAJ?) in Django.
> I've got it working and am doing some clean up and validation work.  A
> few questions:
>
> 1. If a request is invalid, what is the appropriate or common thing to
> do?  Send a JSON error message?  Send a 404?  Something else?
>
> 2. Using the HttpResponse object, what's the correct mimetype for  
> JSON?
>  I've seen application/json and also text/javascript.  (Just looked,
> the JSON RFC says application/json:
> http://www.ietf.org/rfc/rfc4627.txt?number=4627)




What you should do is return either a 'success' or 'failure' key in  
your JSON response_dict. If you're using YAHOO's library, it will  
then route appropriately to the success or failure method of your  
callback object.  Take a look at James Bennett's write up about this:

http://www.b-list.org/weblog/2006/07/31/django-tips-simple-ajax- 
example-part-1
http://www.b-list.org/weblog/2006/08/05/django-tips-simple-ajax- 
example-part-2

And the mimetype should be application/json, this prevents security  
holes from happening, see:

http://jibbering.com/blog/?p=514

text/javascript is not really appropriate as json is not strictly  
Javascript, but a subset of Javascript.

Don


--~--~---------~--~----~------------~-------~--~----~
 You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to