$.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"); }
随机推荐
- RGB颜色表-网址不见了看这里
英文不翻译 翻译成中文
- CI框架源码学习笔记5——Hooks.php
接着Benchmark.php往下看,下一个引入的文件是Hooks.php,我们称之为钩子.它的目的是在不改变核心文件的基础上,来修改框架的内部运作流程.具体使用方法参见手册http://codeig ...
- docker log: containerid-json.log 文件disappear,问题排查及解决方案
问题排查: 运行 #docker info 查阅资料,知道了docker的logging driver相关理论:https://docs.docker.com/engine/admin/loggi ...
- 并查集【洛谷P1197】 [JSOI2008]星球大战
P1197 [JSOI2008]星球大战 题目描述 很久以前,在一个遥远的星系,一个黑暗的帝国靠着它的超级武器统治着整个星系. 某一天,凭着一个偶然的机遇,一支反抗军摧毁了帝国的超级武器,并攻下了星系 ...
- Ubuntu安装SHH服务
1.打开"终端窗口",输入"sudo apt-get update"-->回车-->"输入当前登录用户的管理员密码"--> ...
- CF796A Buying A House 模拟
Zane the wizard had never loved anyone before, until he fell in love with a girl, whose name remains ...
- .net mvc 框架实现后台管理系统 3
左侧菜单实现 默认html <div class="layui-side layui-bg-black h-slide"> <div class="la ...
- python内存相关问题
想要弄清楚内存相关的问题,就要理清楚:变量.内存地址.值之间的关系:1.程序里什么时候分配新的内存地址?答:1.定义一个变量,内存就开辟一个内存空间,分配一个内存地址. 特殊: 如:a=687 a=1 ...
- spring boot 1.4.2.RELEASE+Thymeleaf+mybatis 集成通用maper,与分页插件:
<parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot ...
- git学习--远程分支删除
查看远程分支 git branch -r 使用下面两条命令来删除远程分支 git branch -r -d origin/branch-name git push origin :branch-na ...