JQuery getJSON 回调返回空数据

1 投票
1 回答
4142 浏览
提问于 2025-04-15 22:36

我有一个getJSON的调用,它能正常回调,但数据变量却是空的。下面发布的python代码是通过getJSON调用的demandURL执行的。有什么想法吗?

javascript:

var demandURL = "/demand/washington/";
$.getJSON(demandURL, function(data) {
     console.log(data);
});

python:

data = {"demand_count":"one"}
json = simplejson.dumps(data)
return HttpResponse(json, mimetype="application/json")

1 个回答

0

把你用的 getJSON 换成 ajax 调用,这样你就能看到错误信息了。可以试试下面这样的写法:

$.ajax({
  url: url,
  dataType: 'json',
  data: data,
  success: function(data) {
    console.log(data);
  },
  error: function(XMLHttpRequest, textStatus, errorThrown) {
    console.log(textStatus, errorThrown);
  }
});

撰写回答