python请求.args用ajax pos清空

2024-04-19 15:15:43 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图通过ajaxpost将数据传递到当前的pyapi,但在打印传递的值时总是得到ImmytableMultiDict<[]>。你知道吗

代码如下:

@app.route('/users/new', methods=['POST'])
@handle_exceptions_in_web_views
def intromeeting():
   print(request.args)
   firstname, lastname = parse_user_request_args(request.args)

def parse_user_request_args(args):

   firstname = args.get('firstName') or ''

   lastname = args.get('lastName') or ''

   return firstname, lastname

js代码:

$.post('users/new', {

    firstName: 'test first name',
    lastName: 'test last name'

}).done(function(res){

    console.log(res)

}).fail(function (err){

    console.log(err)

}); 

我也尝试使用$.ajax,但得到了相同的结果。我应该将数据移动到窗体还是smth?你知道吗


Tags: or数据代码newgetparserequestdef