jQuery.post( url, [data], [callback], [type] ) :使用POST方式来进行异步请求

参数:

url (String) : 发送请求的URL地址.

data (Map) : (可选) 要发送给服务器的数据,以 Key/value 的键值对形式表示。

callback (Function) : (可选) 载入成功时回调函数(只有当Response的返回状态是success才是调用该方法)。

type (String) : (可选)官方的说明是:Type of data to be sent。其实应该为客户端请求的类型(JSON,XML,等等)

这是一个简单的 POST 请求功能以取代复杂 $.ajax 。请求成功时可调用回调函数。如果需要在出错时执行函数,请使用 $.ajax。示例代码:

Ajax.aspx:

Response.ContentType = "application/json";Response.Write("{result: '" + Request["Name"] + ",你好!(这消息来自服务器)'}");

jQuery 代码:

$.post("Ajax.aspx", { Action: "post", Name: "lulu" },         function (data, textStatus){             // data 可以是 xmlDoc, jsonObj, html, text, 等等.       //this;     // 这个Ajax请求的选项配置信息,请参考jQuery.get()说到的this      alert(data.result);        }, "json");
 $.post("/user/CheckUserName", { userName: userName }, function (result) { alert(result) }, "text");

点击提交:

这里设置了请求的格式为"json":

$.ajax()这个是jQuery 的底层 AJAX 实现。简单易用的高层实现见 $.get, $.post 等。
这里有几个Ajax事件参数:beforeSend success complete ,error 。我们可以定义这些事件来很好的处理我们的每一次的Ajax请求。

$.ajax({ url: 'stat.php',
type: 'POST',
data:{Name:"keyun"},
dataType: 'html',
timeout: 1000,
error: function(){alert('Error loading PHP document');},
success: function(result){alert(result);}
});

//add by Q at 2008.11.25

今天遇到一个jquery的post的小问题

因为要批量删除,所以开始用循环的post到那个url,然后刷新本页

这就出现问题了

$("input[@name='qa_checkbox']").each(function() {     if($(this).attr('checked') == undefined)     {                      }     else     {         $.post(url,{Action:"POST"},function(data){alert(data);window.location.reload();}, "text");                      } })

这么用的话 只能删除第一条数据;

$("input[@name='qa_checkbox']").each(function() {     if($(this).attr('checked') == undefined)     {                      }     else     {         $.post(url+$(this).val(),{Action:"POST"},function(data){alert(data);}, "text");                      } })
window.location.reload();

这样用的话,虽然可以删除,也能刷新本页,貌似reload是在post的function之前运行,但是post会报错,其中原因有待研究;

最终想了折中的办法

$("input[@name='qa_checkbox']").each(function()         {             if($(this).attr('checked') == undefined)             {                              }             else             {                 url = url + $(this).val() + '_';                              }         })         $.post(url,{Action:"POST"},function(data){alert(data);window.location.reload();}, "text");     }

随机推荐

  1. 「BZOJ 2440」完全平方数「数论分块」

    题意 \(T\)组数据,每次询问第\(k\)个无平方因子的数(\(1\)不算平方因子),\(T\leq 50,k\leq 10^9\) 题解 \(k\)的范围很大,枚举肯定不行,也没什么奇妙性质,于是 ...

  2. hdu2328(后缀数组 + 二分)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=2328 题意: 求 n 个串的字典序最小的最长公共子串 思路: 本题中单个字符串长度不超过 200, ...

  3. nagios安装使用指南

    话不多说,下面开始,nagios具体的介绍,可以搜一下,这篇文章为作者在实际操作中整理出来,写出来的都是负责人的内容~ 环境准备 此文档共用2台服务器的配置,操作系统均为centOS6.7,安装用户都 ...

  4. springboot添加第三方的jar或本地jar

    原文链接:https://www.cnblogs.com/fengli9998/p/8044923.html 由对接支付引入第三方的jar时冒出的问题,如何在springboot项目中来引入第三方的j ...

  5. 4 Values whose Sum is 0(枚举+二分)

    The SUM problem can be formulated as follows: given four lists A, B, C, D of integer values, compute ...

  6. 2016 Multi-University Training Contest 10 || hdu 5860 Death Sequence(递推+单线约瑟夫问题)

    题目链接:http://acm.split.hdu.edu.cn/showproblem.php?pid=5860 题目大意:给你n个人排成一列编号,每次杀第一个人第i×k+1个人一直杀到没的杀.然后 ...

  7. Java换行符

    public static final String NewLineSeparator=System.getProperty("line.separator","\n&q ...

  8. js Form表单转json格式,及后台接收(多种方法)

    转载:https://blog.csdn.net/qq_40138785/article/details/81533015 一.serialize()方法格式:var data = $("# ...

  9. java拦截器的使用

    转载: https://www.cnblogs.com/liangblog/p/7234757.html https://blog.csdn.net/reggergdsg/article/detail ...

  10. CENTOS 7 install mariadb 10.3

    CENTOS install mariadb 10.3 cat >/etc/yum.repos.d/MariaDB.repo << 'EOF' [mariadb] name = Ma ...