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");

点击提交:

这里设置了请求的格式为"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. 【转】oracle远程导入数据库

    源地址:http://blog.chinaunix.net/uid-20980141-id-447996.html

  2. 缩点+spfa最长路【bzoj】 1179: [Apio2009]Atm

    [bzoj] 1179: [Apio2009]Atm Description Siruseri 城中的道路都是单向的.不同的道路由路口连接.按照法律的规定, 在每个路口都设立了一个 Siruseri ...

  3. Java json字符串对比

    public class JsonUtil { public static boolean compareJsonText(String str1, String str2) { return com ...

  4. java中检测网络是否相通

    转载:https://www.cnblogs.com/moon-jiajun/p/3454576.html 1 package com.cjj.client; 2 3 import java.io.I ...

  5. pl/sql declare loop if

    -- 1.判断表是否存在,如果存在则drop表 -- 2.创建表 -- 3.插入1W条数据 -- 4.每1K条commit一次 declare v_table ):='STUDENT'; --表名 v ...

  6. centos7-网络与防火墙常用命令

    1.网络配置 vi /etc/sysconfig/network-scripts/ifcfg-ens33 BOOTPROTO="static" IPADDR=192.168.163 ...

  7. js和jq中常见的各种位置距离之offset和offset()的区别(三)

    offsetLeft:元素的边框的外边缘距离与已定位的父容器(offsetparent)的左边距离(不包括元素的边框和父容器的边框). offset().left:返回的是相对于当前文档的坐标,使用o ...

  8. PHP artisan

    Artisan 是 Laravel 提供的 CLI(命令行接口),它提供了非常多实用的命令来帮助我们开发 Laravel 应用.前面我们已使用过 Artisan 命令来生成应用的 App Key 和控 ...

  9. Dev Express Report 学习总结(六)Dev Express Reports自定义Summary

    在我们使用DevExpress开发报表的过程中,对于页面中复杂的数据合计,我们可能会使用到自定义Summary.下面通过一个例子来进行说明: 首先,我建立了如上图所示的报表页面,其中的数据源来自cla ...

  10. Silverlight 用DependencyProperty 自定义ImageButton控件 定义属性

    为ImageButton自定义IconSource和Contents属性 xaml代码 <UserControl x:Class="SilverlightCreate.Silverli ...