使用这段代码,我正在尝试从服务器获取数据
$scope.get_file_list = function() {
delete $http.defaults.headers.common['X-Requested-With']; //We don't wat OPTIONS but GET request
$http({method: 'GET', url: backendUrl + '/session/' + $scope.id + '/list'})
.success(function(data, status, headers, config) {
// ...
})
.error(function(data, status, headers, config) { console.log(
'error\ndata: '+data+
'\nstatus: '+status); });
服务器:
from flask import Flask, request
from werkzeug import secure_filename
import glob, os
app = Flask(__name__)
@app.route('/session/<session_id>/list', methods = ['GET'])
def get_file_list(session_id):
# ...
@app.route('/session/<session_id>/upload', methods = ['POST'])
def upload_file(session_id):
# ...
if __name__ == '__main__':
app.run(debug = True, port=80)
这是浏览器的控制台输出
[18:58:37.409] "error
data:
status: 0
服务器以代码 200 响应,当我使用浏览器对其进行测试时,一切正常(服务器发送数据而控制台中没有任何警告)。也许我应该用 jQuery 来做这件事?