文章内容
2018/10/28 18:01:06,作 者: 黄兵
flask使用ajax的方式提交json数据
最近在flask中使用ajax的方式提交json数据,写法如下:
$.ajax({
type: 'POST',
data: {ajax_item_id: JSON.stringify(get_param)},
url: '/manage/ajax_get_item',
contentType: "application/json; charset=utf-8",
//contentType: "application/json",
dataType:"json",
success: function (data) {
console.log(data);
}
});后台获取方式:
global get_ajax_id
get_ajax_id = request.values.get('ajax_item_id', 0)但是获得的是0,前台是有数据的。
最后修改成GET方式提交数据:
$.ajax({
type: 'GET',
data: {ajax_item_id: JSON.stringify(get_param)},
url: '/manage/ajax_get_item',
contentType: "application/json; charset=utf-8",
//contentType: "application/json",
dataType:"json",
success: function (data) {
console.log(data);
}
});
console.log(get_param);views.py
global get_ajax_id
get_ajax_id = request.values.get('ajax_item_id', 0)获取到了数据,但是具体问题出在哪里,明天继续研究。
哪位知道哪里出错了,给说一声谢谢。
黄兵个人博客原创。
转载请注明出处:黄兵个人博客 - flask使用ajax的方式提交json数据
评论列表