Hi Pasha,

1. Try using a dict instead of a list:
data = {
    'items': [{'id':'2','quant':3},{'id':4','quant':1}]
}

2. could you provide the relevant part of the view?

I expect something like:

from django.http import HttpResponse
from django.utils import simplejson

def update_cart(request):
    data = {'items': [{'id':'2','quant':3},{'id':4','quant':1}]}
    ...
    return HttpResponse(
        simplejson.dumps(data),
        content_type='application/javascript; charset=utf8'
    )

Answer based on:
* 
http://stackoverflow.com/questions/798111/how-do-i-json-serialize-a-python-dictionary
* 
http://www.b-list.org/weblog/2006/jul/31/django-tips-simple-ajax-example-part-1/
* personal experience :-)

Good luck, RR

On May 9, 12:56 pm, Паша Тявин <vinogra...@gmail.com> wrote:
> Hello. I'm newbie and trying to make a simple shopping cart using anonymous
> session under ajax control.
> I have a special url "/update_cart/" for only post request from the the page
> "/product/" and I made a dictionary "request.session['cart']" with a text
> like [{'id':'2','quant':3},{'id':4','quant':1}].
> The answer from "/update_cart/" has a mimetype "application/json" and I can
> see the answer in the ff firebug, but the client js cathes it like "[Object
> object]".
> How can I read the data not like [object, object], but
> like  [{'id':'2','quant':3},{'id':4','quant':1}] ?
>
> The question, maybe not for the using django, but for js. So the next
> question is: Am I doing the cart in a django way? Or should I do something
> different?

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to