ajax - The right way to send some data alongside with form -
i have page of user oders, displayed products in cart , form fields like: address
, mobile number
etc. catch submit
jquery, , need send next data server: form , dictionary {id_of_product:choosen_ammount}
. need send dictionary, because check whether there such ammount of product user choose. if not, send error. use ajax. send data looks:
data = { form : $(this).serialize(), products: somedict }
in django next:
from urlparse import parse_qs form = parse_qs(request.post['form']) if request.post: order_form = orderform(data=form)
but faced problem: saves not correct data database. example saves text string like:[u'\xd0\x9a\xd0\xb8\xd1\x97\xd0\xb2']
. tried check returns order_form.cleaned_data['address_city']
, returns same. so, how solve problem?
use django's querydict.
from django.http import querydict # encode form data byte string. form_data = querydict(request.post['form'].encode('ascii')) order_form = orderform(data=form_data)
note: first part of problem: pass json , deserialize form in django
Comments
Post a Comment