weixin_33709590 2016-01-09 08:42 采纳率: 0%
浏览 24

使用Ajax的未定义查询集

here is 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)

here is the ajax script

<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>

here is the queryset

minpricestore : [u'z store']
minprice: [1999]
minId:[1]

when i console.log it says undefined

ajax is working fine but unable to display the queryset.I get undefined when using alert.what can i do to to display the above queryset? Thanks in Advance

  • 写回答

1条回答 默认 最新

  • weixin_33720078 2016-01-09 09:51
    关注

    Add the dataType open in Ajax call

    dataType: "json",
    
    评论

报告相同问题?

悬赏问题

  • ¥20 西门子S7-Graph,S7-300,梯形图
  • ¥50 用易语言http 访问不了网页
  • ¥50 safari浏览器fetch提交数据后数据丢失问题
  • ¥15 matlab不知道怎么改,求解答!!
  • ¥15 永磁直线电机的电流环pi调不出来
  • ¥15 用stata实现聚类的代码
  • ¥15 请问paddlehub能支持移动端开发吗?在Android studio上该如何部署?
  • ¥20 docker里部署springboot项目,访问不到扬声器
  • ¥15 netty整合springboot之后自动重连失效
  • ¥15 悬赏!微信开发者工具报错,求帮改