1 回答
TA贡献1794条经验 获得超8个赞
我改为使用application/jsonPOST 请求而不是默认值application/x-www-form-urlencoded,这似乎解决了"null"当参数之一为空或丢失时请求发送字符串而不是空字符串的问题。
let params = new URLSearchParams(location.search);
let url_id = params.get('id');
let url_language = params.get('language');
const url = 'http://localhost:8080/start-analysis';
$.ajax({
url: url,
type: 'POST',
dataType: 'json',
contentType: 'application/json',
data: JSON.stringify({'playlist': url_id,'language': url_language}),
success: function(results) {
...
},
error: function(response, status, error) {
...
}
});
后端接收它的方式如下:
class StartAnalysis(BaseHandler):
def post(self):
data = json.loads(self.request.body)
playlist = data['playlist']
language = data['language']
添加回答
举报