ajax post获得json,从AJAX POST获取JSON数据的问题

AJAX调用如下所示:json_dictionary = {url : url, profile_dict: dictionary, final_dict : final_dictionary}

$.ajax({

url: "https://localhost:8090/add_profile_data",

type: "POST",

data: JSON.stringify(json_dictionary),

contentType:'application/json',

success:function() {

console.log('added profile data')

}

})

客户端如下所示:

^{pr2}$

这样就可以了,打印的结果是

另外,当我打印data对象时,所有东西都在那里。在

但是,当我尝试:@app.route('/add_profile_data', methods=['POST', 'GET', 'OPTIONS'])

def add():

data = request.json

print(data.keys())

我得到一个错误:AttributeError: 'NoneType' object has no attribute 'keys'

我不明白为什么会这样?有什么想法吗?在

更新:

将服务器更改为这个,现在看到NoneType为{}

服务器:@app.route('/add_profile_data', methods=['POST', 'GET', 'OPTIONS'])

def add():

data = request.json

print(type(data))

print(data.keys())

回应:

127.0.0.1 - - [04/Jan/2017 09:13:47] "OPTIONS /add_profile_data HTTP/1.1" 500 -

Traceback (most recent call last):

File "/Library/Python/2.7/site-packages/flask/app.py", line 2000, in __call__

return self.wsgi_app(environ, start_response)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1991, in wsgi_app

response = self.make_response(self.handle_exception(e))

File "/Library/Python/2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function

return cors_after_request(app.make_response(f(*args, **kwargs)))

File "/Library/Python/2.7/site-packages/flask/app.py", line 1567, in handle_exception

reraise(exc_type, exc_value, tb)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1988, in wsgi_app

response = self.full_dispatch_request()

File "/Library/Python/2.7/site-packages/flask/app.py", line 1641, in full_dispatch_request

rv = self.handle_user_exception(e)

File "/Library/Python/2.7/site-packages/flask_cors/extension.py", line 161, in wrapped_function

return cors_after_request(app.make_response(f(*args, **kwargs)))

File "/Library/Python/2.7/site-packages/flask/app.py", line 1544, in handle_user_exception

reraise(exc_type, exc_value, tb)

File "/Library/Python/2.7/site-packages/flask/app.py", line 1639, in full_dispatch_request

rv = self.dispatch_request()

File "/Library/Python/2.7/site-packages/flask/app.py", line 1625, in dispatch_request

return self.view_functions[rule.endpoint](**req.view_args)

File "/Users/morganallen/Dropbox/Coding_Projects/Prediction_Server/prediction_v2.py", line 172, in add

print(data.keys())

AttributeError: 'NoneType' object has no attribute 'keys'

为什么我看到{}?在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值