简体   繁体   English

jQuery getJSON回调返回空数据

[英]JQuery getJSON Callback Returning Null Data

I have a getJSON call that is called back correctly, but the data variable is null. 我有一个getJSON调用,可以正确地回调它,但是数据变量为null。 The python code posted below is executed by the getJSON call to the demandURL. 下面发布的python代码由对demandURL的getJSON调用执行。 Any ideas? 有任何想法吗?

javascript: 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")

Switch out your getJSON with an ajax call so you can have a look at the error message. 使用ajax调用切换出getJSON,以便您查看错误消息。 Try something like this: 尝试这样的事情:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM