我有以下简单的代码,但 getjson 不知何故不起作用。我的 python 脚本正确打印了一个 json 编码的值。任何人都可以提出任何建议吗?
HTML
<!DOCTYPE html>
<html>
<head>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.8.0/jquery.min.js" type="text/javascript"></script>
</head>
<body>
<script type="text/javascript">
$.getJSON('weather.py', function(data) {
console.log('callback works');
});
</script>
</body>
</html>
Python:
import json
from json import load
from urllib2 import urlopen
from pprint import pprint
import pycassa
from pycassa.pool import ConnectionPool
from pycassa.columnfamily import ColumnFamily
from pycassa.index import *
pool = pycassa.ConnectionPool('hr')
crime = pycassa.ColumnFamily(pool, 'crime')
##Pull all of the data and convert to JSON
data = json.dumps([columns for key, columns in crime.get_range()])
return data