我传递数据到数组,我想通过ajax发送这个数组到我的views.py。但是在运行时只有错误块被执行。
JQuery的
<script type="text/javascript">
var arr=[];
$(document).ready(function(){
$(".addtocart").click(function(){
arr.push($(this).closest('tr').find('td:eq(0)').text());
});
$("#show").click(function(){
$.ajax({
type: 'POST',
url:'{% url "curr_order" %}',
data: {'arr[]': arr},
success:function(data){
alert(data.order)
},
error: function(){
alert("Error");
}
});
});
});
</script>
views.py
def curr_order(request):
if request.is_ajax():
order = request.POST.getlist('arr[]')
response = {'order': order}
return HttpResponse(json.dumps(response), content_type='application/json')
urls.py
url(r'^curr_order/$',views.curr_order, name ='curr_order')
我的问题是:
1)现在运行警告框与错误显示。为什么不成功阻止不执行?我该如何纠正它?
2)如何显示所有数组元素? data.order
不会显示我认为的所有元素。
谢谢!
检查错误,那么 –
使用控制台的网络选项卡,看看具体的状态代码和错误描述。 –