Django + Ajax は初めてです。私の問題は、ajaxPOST
リクエストから値を取得できないことです。を使用していjquery post
ます。
私の仕事は、ドラッグ可能なリスト項目をソートすることです。ドラッグアンドドロップは問題ありません。POST
リクエストから値を取得することが問題です。戻るMultiValueDictKeyError
"Key 'ages' not found in <QueryDict: {u'action': [u'updateRecords'], u'ages[]': [u'80', u'81', u'79', u'82', u'83', u'84', u'85', u'86']}>"
ここに私のajaxがあります:
$(function() {
var url = ""; /* won't place it*/
$("ul#ages").sortable({ opacity: 0.6, cursor: 'move', update: function() {
var order = $(this).sortable("serialize") + '&action=updateRecords';
$.post(url, order, function(theResponse){
alert('success');
});
}
});
});
ここにビューがあります:
if request.is_ajax():
if request.POST['action'] == "updateRecords":
update_record_array = request.POST['ages']
order_counter = 1;
for record_id in update_record_array:
Age.objects.filter(id=record_id).update(order_id=order_counter)
order_counter += 1
誰でも私を助けることができますか?
ありがとう!