使用Ajax的未定义Queryset
Undefined Queryset with Ajax
这里是views.py
if request.is_ajax():
minpricestore = list(StoreProduct.objects.filter(product__id=productobj).values_list('store__StoreName' , flat=True).annotate(Min('price')))
print minpricestore
minprice = list(StoreProduct.objects.filter(product__id=productobj).values_list('price' , flat=True).annotate(Min('price')).order_by('price'))
print minprice
minId = list(StoreProduct.objects.filter(product__id=productobj).values_list('store__id' , flat=True).annotate(Min('price')).order_by('price'))
print minId
data = {
'minpricestore' : minpricestore ,
'minprice' : minprice ,
'minId' : minId
}
JsonResponse(data)
这是ajax脚本
<script type="text/javascript">
function sendProduct(event, productId) {
event.preventDefault();
var data = { productId : productId };
// Send productId as query param of url
$.ajax({
type: "GET",
url: "{{instance.get_absolute_url}}",
data: data,
success: function(data) {
alert(data.minprice)
},
error: function(response, error) {
alert(error);
}
});
}
</script>
这是查询集
minpricestore : [u'z store']
minprice: [1999]
minId:[1]
当我console.log时,它说未定义
ajax工作正常,但无法显示查询集。我在使用alert时未定义。我可以做些什么来显示上面的查询集?提前感谢
添加在Ajax调用中打开的dataType
dataType: "json",
相关文章:
- 为什么“;未定义的“;在JavaScript中结束循环
- 要求未定义JS回调参数
- 如何检查管道中未定义的项目
- TypeError:无法读取属性'推'未定义的JavaScript
- $window.ga在AngularJS事件中未定义
- 未捕获的TypeError无法读取未定义的属性socialsharing
- 为什么grunt contrib connect的中间件选项的第三个参数是未定义的
- 无法获取属性'selectedIndex'的未定义引用或null引用
- 如何消除代码中的未定义和其他问题
- 未捕获的ReferenceError:$未定义
- this.router在AngularJS 2中未定义
- 未捕获的类型错误:无法读取属性'删除'的未定义
- 节点fs.stat名称未定义
- 尝试在PHP中回显输入文本时出现未定义的索引错误
- Jquery未定义函数正在停止其他操作
- AngularJS指令出错-无法读取属性'编译'的未定义
- 这.SOMETHING 总是返回未定义的 - extjs
- 无法获取属性'Id'使用Knockout.js的未定义或空引用API
- Wordpress中带有JQuery Accordion的未定义匿名函数
- 使用Ajax的未定义Queryset