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. 青蛙的约会 - poj 1061(扩展欧几里得)

    分析:这个东西在数论里面应该叫做不定方程式,可以搜一下,有很精彩的证明,先求出来方程式的一组特解,然后用这组特解来求通解,但是求出来特解之后怎么求这些解里面的最小非负x值?我们知道 x = x0 + ...

  2. hdoj 1061 Rightmost Digit【快速幂求模】

    Rightmost Digit Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)T ...

  3. weblogic 日志介绍

    1.server.log 该日志记录的是服务(包括admin server 和 app server)启动过程中和关闭过程中的日志,还包括部署在服务上面的应用,在运行过程中所产生的日志. server ...

  4. mysql in查询 结果乱序 引发的思考

    Mysql in查询 结果集 乱序 SQL: select * from table where id IN (3,6,9,1,2,5,8,7); 这样的情况取出来后,其实,id还是按1,2,3,4, ...

  5. 超级好用的国际汇兑平台--Transferwise

    一年的CSC留学快结束了,手里还剩了些积攒下来的美元.就国内那点博士的工资,出来一趟好不容易领了点美元可不想都给银行汇兑的手续费给吞了去. 这两天英国退欧,英镑大跌,美元有涨,是个把手里的美元寄回国换 ...

  6. thinkphp中使用PHPEXCEL导入数据

    导入方法比较简单 但必须考虑到Excel本身单元格格式问题 例如以0开头的字符串读出来被去掉了前导0 成为float型而丢失一位 必须进行处理 <?php /** * Author lizhao ...

  7. 设置UWP程序自启动(Automate launching Windows 10 UWP apps)

    在开发UWP程序的过程中,有时候需要设置程序的自启.本人实现的步骤如下: 1.在VS中激活Protocol (Package.appxmanifest --> Declarations --&g ...

  8. 如何解决 SogouIinput not enough space for thread data ?? 虚拟内存

    问题:总是提示没有足够的空间读写数据 上图: 原因: 可能是虚拟内存设置了过大了[我不知道明白是不是也是这样,我出现这个问题就是因为我把虚拟内存设置成了4G,我的物理内存是2G的] 具体问题具体分析, ...

  9. Eclipse启动 报错[Failed to load the JNI shared library jvm.dll

    准备要做java服务器,在安装开发环境时,启动Eclipse报错[Failed to load the JNI shared library jvm.dll] 研究了下,造成错误的原因是由于eclip ...

  10. flume学习安装

    近期项目组有需求点击流日志须要自己收集,学习了一下flume而且成功安装了.相关信息记录一下. 1)下载flume1.5版本号  wget http://www.apache.org/dyn/clos ...