【问题标题】:django-ajax json responsedjango-ajax json 响应
【发布时间】:2012-03-23 10:44:30
【问题描述】:

我有一个 django url : '127.0.0.1:8000/showsym' 映射到查看返回的 json 响应

def get_symptoms(request):
    bp=BodySubPart.objects.get(body_subpart="head")
    data1=bp.symptoms.all()
    data = serializers.serialize('json', data1)
    return HttpResponse(data,mimetype='application/json')

现在我正在尝试在 ajx_form.html 中解析它,代码是:

<html>
<head>
<title>Hist</title>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"     type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
(function() {
$.get('127.0.0.1:8000/showsym/', function(data1) {
       alert(data1);
    });
});

</script>

</body>
</html>

但它没有给我任何输出 页面变为空白

请帮帮我

【问题讨论】:

    标签: javascript python django jquery


    【解决方案1】:

    这是因为您的代码试图获取 url:/127.0.0.1:8000/showsym/

    127.0.0.1:8000/showsym/ 更改为/showsym/

    我建议你使用$.getJSON 并命名网址,假设/showsym 的url name 是showsym:

    $(document).ready(function() {
        $.getJSON('{% url showsym %}', function(data, textStatus, jqXHR) {
            alert(data);
        })
    })
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-03-13
      • 2014-01-18
      • 1970-01-01
      • 2016-09-16
      • 2019-05-15
      • 2016-12-29
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多