flask接受jquery ajax传递过来的参数
2015-07-23 17:49
561 查看
I have been working with similar functionality and after a bit of messing around with the ajax and python, this is what I came up with for python reading the ajax dataJavaScript:
在java和nodejs中可以这么写,但flask不能!
var data = { data: JSON.stringify({ "value":'asdf' }) } }; $.ajax({ url:"/", type: 'POST', data: data, success: function(msg){ alert(msg); } })Python:
from flask import json @app.route("/", methods=['POST']) def get_data(): data = json.loads(request.form.get('data')) ss = data['value'] return str(ss)
注意:
javascript 不能如下写法,不知为什么:
$.ajax({ url:"/", type: 'POST', data: {"value":"val1"}, success: function(msg){ alert(msg); } })
在java和nodejs中可以这么写,但flask不能!
相关文章推荐
- 关于在jquery动态修改css,html中,mouseenter,mouseleave,click等方法失效的处理
- jquery validationengine验证
- jQuery静态方法parseJSON方法使用和源码分析
- jQuery报错:
- jQuery基本方法随笔
- jquery日期格式化
- Jquery Mobile 中绑定事件
- jQuery判断获得的对象是否存在的方法
- jquery easyui树形菜单调用点击事件例子
- js jquery 杂记
- jquery 插件写法笔记
- jquery实现简单的轮换出现效果实例
- jquery实现简单实用的打分程序实例
- 实习小结四:如何使用jQuery实现鼠标移动改变Tab
- 点击页面其它地方隐藏层
- jQuery获取对象
- jQuery 中的事件冒泡和阻止默认行为
- jQuery EasyUI 教程
- JQuery学习笔记
- jquery判断页面、图片是否加载完成