$.ajax、$.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"); }
随机推荐
- Scrapy 中 Request 对象和 Response 对象的各参数及属性介绍
Request 对象 Request构造器方法的参数列表: Request(url [, callback=None, method='GET', headers=None, body=None,co ...
- 【bzoj4800】: [Ceoi2015]Ice Hockey World Championship dfs
[bzoj4800]: [Ceoi2015]Ice Hockey World Championship N<=40所以如果直接dfs背包会TLE 考虑Meet-in-the-middle 如果把 ...
- P4199 万径人踪灭 FFT + manacher
\(\color{#0066ff}{ 题目描述 }\) \(\color{#0066ff}{输入格式}\) 一行,一个只包含a,b两种字符的字符串 \(\color{#0066ff}{输出格式}\) ...
- CF1093E Intersection of Permutations 树状数组套权值线段树
\(\color{#0066ff}{ 题目描述 }\) 给定整数 \(n\) 和两个 \(1,\dots,n\) 的排列 \(a,b\). \(m\) 个操作,操作有两种: \(1\ l_a\ r_a ...
- 洛谷4316 绿豆蛙的归宿(DAG递推/概率dp)
题目大意: 给定一个DAG,求起点到终点的路径长度期望 根据题意可以知道每一条边都有一定概率被走到 那么\(\displaystyle\begin{aligned} Ans = \sum_{e \in ...
- ArcGIS api for javascript-图层控制(图层树)
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...
- Gym - 101845D 计算几何
Ignacio is a famous mathematician, some time ago he was married with Dolly, a famous scientific, at ...
- uversion5 怎么添加设备
实时 点击网址去它的官网下载,然后选择自己的设备组,Dfg ,下载下来的是一个安装包,直接安装即可
- firefox浏览本地网站慢的问题
用火狐调试本地站点网站,总感觉有点迟钝 经查,原来是火狐会检测网站来源,具体工作原理不详 解决办法 依次打开:C:\Windows\System32\drivers\etc 用记事本或editplus ...
- jupyter notebook初步使用
Jupyter Notebook(此前被称为 IPython notebook)是一个交互式笔记本,支持运行 40 多种编程语言.在本文中,我们将介绍 Jupyter notebook 的主要特性,以 ...