我有一个简单的python脚本,它通过以下方式与API交互:
RUN_URL = u'https://api.hackerearth.com/v3/code/run/'
CLIENT_SECRET = '***'
source = "print 'Hello World'"
data = {
'client_secret': CLIENT_SECRET,
'async': 0,
'source': source,
'lang': "PYTHON",
'time_limit': 10,
'memory_limit': 262144,
}
r = requests.post(RUN_URL, data=data)
print r.json()
然而,当尝试使用jquery post方法实现相同的效果时,我根本没有得到响应
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<title>Random</title>
<script src="https://code.jquery.com/jquery-1.10.2.js"></script>
</head>
<body>
<script>
var RUN_URL = "https://api.hackerearth.com/v3/code/run/"
var CLIENT_SECRET = "***"
var source = "print 'Hello World'"
var data = {
client_secret: CLIENT_SECRET,
async: 0,
source: source,
lang: "PYTHON",
time_limit: 5,
memory_limit: 262144,
}
$.post(RUN_URL, data, function (result) {
alert(result);
});
</script>
</body>
</html>
我无法理解我哪里出错了,我已经尝试了所有可以想到的事情。
PS:前端很新鲜