http://www.runoob.com/jquery/jquery-ref-ajax.html

http://jun1986.iteye.com/blog/1399242

下面是jQuery官方给出的完整的Ajax事件列表:

    • ajaxStart (Global Event)
      This event is broadcast if an Ajax request is started and no other Ajax requests are currently running.

      • beforeSend (Local Event)
        This event, which is triggered before an Ajax request is started, allows you to modify the XMLHttpRequest object (setting additional headers, if need be.)
      • ajaxSend (Global Event)
        This global event is also triggered before the request is run.
      • success (Local Event)
        This event is only called if the request was successful (no errors from the server, no errors with the data).
      • ajaxSuccess (Global Event)
        This event is also only called if the request was successful.
      • error (Local Event)
        This event is only called if an error occurred with the request (you can never have both an error and a success callback with a request).
      • ajaxError (Global Event)
        This global event behaves the same as the local error event.
      • complete (Local Event)
        This event is called regardless of if the request was successful, or not. You will always receive a complete callback, even for synchronous requests.
      • ajaxComplete (Global Event)
        This event behaves the same as the complete event and will be triggered every time an Ajax request finishes.
    • ajaxStop (Global Event)
      This global event is triggered if there are no more Ajax requests being processed.

$.post、$.get是一些简单的方法,如果要处理复杂的逻辑,还是需要用到jQuery.ajax()

一、$.ajax的一般格式

$.ajax({

type: 'POST',

url: url ,

data: data ,

success: success ,

dataType: dataType

});

二、$.ajax的参数描述

参数 描述

url 必需。规定把请求发送到哪个 URL。
data 可选。映射或字符串值。规定连同请求发送到服务器的数据。
success(data, textStatus, jqXHR) 可选。请求成功时执行的回调函数。
dataType

可选。规定预期的服务器响应的数据类型。

默认执行智能判断(xml、json、script 或 html)。

三、$.ajax需要注意的一些地方:

1.data主要方式有三种,html拼接的,json数组,form表单经serialize()序列化的;通过dataType指定,不指定智能判断。

2.$.ajax只提交form以文本方式,如果异步提交包含<file>上传是传过不过去,需要使用jquery.form.js的$.ajaxSubmit

通过 jQuery 使用 AJAX

http://dormousehole.readthedocs.org/en/latest/patterns/jquery.html

Flask中服务器端怎样接受ajax发送的json?

Flask 如何响应 JSON 数据

一、一个小小的例子,展示 Flask 如果响应 JSON 数据

flask-ajax-json

Flask 代码:

Code example:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

# -*- coding: utf-8 -*-

"""

ajax Example

~~~~~~~~~~~~~~

一个简单的应用,展示了 Flask 如果响应 JSON 数据。

:copyright: (c) 2014 by Innes Luo.

:license: BSD, see LICENSE for more details.

"""

fromflaskimportFlask, jsonify, render_template, request

app=Flask(__name__)

@app.route('/', methods=['POST','GET'])

defindex():

ifrequest.method=='POST':

n=[request.form.get(x,0,type=float)forxin{'n1','n2','n3'}]

returnjsonify(max=max(n),min=min(n))

else:

returnrender_template('index.html')

if__name__=='__main__':

app.run()

模板代码:

Code example:

1

2

3

4

5

6

7

8

9

10

11

12

13

14

15

16

17

18

19

20

21

22

23

24

25

26

27

28

29

30

31

32

33

34

35

36

37

38

39

40

41

42

43

44

<htmlxmlns="http://www.w3.org/1999/html"xmlns="http://www.w3.org/1999/html">

<head>

<metacharset="utf-8">

<title>ajax Exampletitle>

    <scripttype=text/javascriptsrc="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-2.1.0.min.js">script>

    <scripttype=text/javascript.>

    var $SCRIPT_ROOT = {{ request.script_root|tojson|safe }};

    function ajaxForm(){

    $.ajax({

    type: 'post',

    url: $SCRIPT_ROOT,

    dataType: 'json',

    data:{

    'n1': $('input[name=n1]').val(),

    'n2': $('input[name=n2]').val(),

    'n3': $('input[name=n3]').val()

    },

    error: function(xhr, err){

    alert('请求失败,原因可能是:' + err + '!')

    },

    success: function(data, textStatus){

    $('#max').text(data.max);

    $('#min').text(data.min);

    }

    });

    return false

    }

    script>

    head>

    body>

    <h1>ajax Exampleh1>

    <formaction=""method="post"onSubmit="return ajaxForm()">

    <p>在下面 3 个文本框中输入数字,然后点击按钮p>

    <inputname="n1"type="text"/>

    <inputname="n2"type="text"/>

    <inputname="n3"type="text"/>

    <inputtype="submit"/>

    <p>最大数:<spanid=max>?span>p>

    <p>最小数:<spanid=min>?span>p>

    form>

    body>

    html>

flask resquest响应POST请求的json数据问题?

http://www.oschina.net/question/2337216_233467

Post函数未添加关键字。

r = requests.post('http://localhost:5000/login',json.dumps(values),headers);

具体参见:

http://www.python-requests.org/en/latest/user/quickstart/#more-complicated-post-requests

http://stackoverflow.com/questions/14112336/flask-request-and-application-json-content-type?rq=1

http://blog.csdn.net/iloveyin/article/details/21444613

Flask jQuery ajax的更多相关文章

  1. flask jQuery ajax 上传文件

    1.html 代码 <div> <form id="uploadForm" enctype="multipart/form-data" > ...

  2. 前端和后端的数据交互(jquery ajax+python flask+mysql)

    上web课的时候老师布置的一个实验,要求省市连动,基本要求如下: 1.用select选中一个省份. 2.省份数据传送到服务器,服务器从数据库中搜索对应城市信息. 3.将城市信息返回客户,客户用sele ...

  3. python Flask JQuery使用说明

    0.前言     近期因为某种原因再次学习Flask框架.借助博客整理相关内容.Flask框架和Apache+PHP存在少许不同,Flask框架中JS和CSS文件存放于一个相对固定的位置. 普通情况下 ...

  4. 教你如何使用flask实现ajax数据入库

    摘要:在正式编写前需要了解一下如何在 python 函数中去判断,一个请求是 get 还是 post. 本文分享自华为云社区<[首发]flask 实现ajax 数据入库,并掌握文件上传>, ...

  5. IE8/9 JQuery.Ajax 上传文件无效

    IE8/9 JQuery.Ajax 上传文件有两个限制: 使用 JQuery.Ajax 无法上传文件(因为无法使用 FormData,FormData 是 HTML5 的一个特性,IE8/9 不支持) ...

  6. jquery ajax解析

    jQuery确实是一个挺好的轻量级的JS框架,能帮助我们快速的开发JS应用,并在一定程度上改变了我们写JavaScript代码的习惯. 废话少说,直接进入正题,我们先来看一些简单的方法,这些方法都是对 ...

  7. jQuery.ajax 根据不同的Content-Type做出不同的响应

    使用H5+ASP.NET General Handler开发项目,使用ajax进行前后端的通讯.有一个场景需求是根据服务器返回的不同数据类型,前端进行不同的响应,这里记录下如何使用$.ajax实现该需 ...

  8. jQuery.ajax(url,[settings])

    概述 通过 HTTP 请求加载远程数据. jQuery 底层 AJAX 实现.简单易用的高层实现见 $.get, $.post 等.$.ajax() 返回其创建的 XMLHttpRequest 对象. ...

  9. jQuery Ajax 实例 ($.ajax、$.post、$.get)

    jQuery Ajax 实例 ($.ajax.$.post.$.get) 转 Jquery在异步提交方面封装的很好,直接用AJAX非常麻烦,Jquery大大简化了我们的操作,不用考虑浏览器的诧异了. ...

随机推荐

  1. record

    http://www.cnblogs.com/90zeng/p/python_translation.html http://www.cnblogs.com/netfocus/p/4478094.ht ...

  2. 天津Uber优步司机奖励政策(1月18日~1月24日)

    滴快车单单2.5倍,注册地址:http://www.udache.com/ 如何注册Uber司机(全国版最新最详细注册流程)/月入2万/不用抢单:http://www.cnblogs.com/mfry ...

  3. Mondriaan's Dream - POJ 2411(状态压缩)

    题目大意:有一些1*2的矩形,现在用这些小矩形覆盖M*N的大矩形,不能重复覆盖,并且要覆盖完全,求有多少种覆盖方式. 分析:可以使用1和0两种状态来表示这个位置有没有放置,1表示放置,0表示没有放置, ...

  4. 银联手机支付(.Net Csharp),3DES加密解密,RSA加密解密,RSA私钥加密公钥解密,.Net RSA 3DES C#

    前段时间做的银联支付,折腾了好久,拼凑的一些代码,有需要的朋友可以参考,本人.Net新手,不保证准确性! 这个银联手机支付没有SDK提供,技术支持也没有.Net的,真心不好搞! RSA加解密,这里有个 ...

  5. Linux安装sonarQube

    安装sonarQube之前,需要先安装JDK和mysql 服务器/home/azrlnx04/下创建三个文件夹,/java ./mysql. /sonar 一:安装JDK (1)打开http://ww ...

  6. textarea文本域

    textarea中换行问题 一旦用nl2br函数处理会多个\n导致十分难看 也无法形成文本框默认效果 前台的html如果用<br/>处理也会给后台的编辑造成困难 所以在编辑的时候这样处理 ...

  7. 自己在安装centos 系统时, 是使用英文安装 成功,现在系统语言为英语,如何设置为中文?

    作为一个linux菜鸟,遇到的问题可谓真多,在虚拟机VMware上安装好centos系统后,心里甚喜,也连上网络了. 一.遇到的问题 but,火狐浏览器浏览网页出现乱码,也不知道怎么解决?所有的中文都 ...

  8. MySQL——修改root密码的4种方法(以windows为例)

    方法1: 用SET PASSWORD命令 首先登录MySQL. 格式:mysql> set password for 用户名@localhost = password('新密码'); 例子:my ...

  9. app 的内存优化

    这篇文章是笔者在开发App过程中发现的一些内存问题, 然后学习了YYKit框架时候也发现了图片的缓存处理 (YYKit 作者联系了我, 说明了YYKit重写imageNamed:的目的不是为了内存管理 ...

  10. Struts2 ValueStack

    一.作用 可以作为一个数据中转站,用在前台和后台数据传递 二.生命周期 ValueStack的生命周期是随着request的创建而创建,随request的销毁而销毁. 三.结构 OgnlValueSt ...