我從互聯網上閱讀了關於JSON的內容,但仍然沒有掌握它。我讀這篇文章與JSON數據和Django ajax請求中的正常數據相混淆
http://webcloud.se/log/AJAX-in-Django-with-jQuery/
我無法理解其中的功能是使用JSON
第一部分def xhr_test(request, format):
if request.is_ajax():
if format == 'xml':
mimetype = 'application/xml'
if format == 'json':
mimetype = 'application/javascript'
data = serializers.serialize(format, ExampleModel.objects.all())
return HttpResponse(data,mimetype)
# If you want to prevent non XHR calls
else:
return HttpResponse(status=400)
我的主要問題是
- 從那裏功能越來越
format
變量 - 格式是
json
意味着給函數的數據是JSON或數據將被recived是JSON - 誰能給我簡單的例子,這將是這個函數的輸出中
data = serializers.serialize(format, ExampleModel.objects.all())
- 我將如何使用這些數據時,我得到響應在jQuery函數
- ,如果我沒有在上面的函數中使用JSON那麼如何將輸入和響應後面會chnage
感謝
非常感謝您的詳細解釋 –