$.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"); }
随机推荐
- UIViewController函数调用顺序
/*********** 0 执行1次而已 ******************/ + (void)load { NSLog(@" 0:%s", __func__); } /*** ...
- 【沽泡学院07】基于ElasticSearch搜索附近的人
1. 为什么要选择ElasticSearch 1)ElasticSearch 优点: 分布式.实时的.Push replication 完全支持Apache Lucene的接近实时的搜索 处理多租户( ...
- springboot jpa mongodb 整合mysql Field in required a bean of type that could not be found Failed to load ApplicationContext
1.完整报错 *************************** APPLICATION FAILED TO START *************************** Descripti ...
- CF567E President and Roads
\(\color{#0066ff}{ 题目描述 }\) 给出一个有向图,从起点走到终点(必须走最短路),问一条边是否一定会被经过,如果不经过它,可以减小它的多少边权使得经过它(边权不能减少到0) \( ...
- CF352A Jeff and Digits
Jeff's got n cards, each card contains either digit 0, or digit 5. Jeff can choose several cards and ...
- [JSOI2009]瓶子和燃料 BZOJ2257 数学
题目描述 jyy就一直想着尽快回地球,可惜他飞船的燃料不够了.有一天他又去向火星人要燃料,这次火星人答应了,要jyy用飞船上的瓶子来换.jyy的飞船上共有 N个瓶子(1<=N<=1000) ...
- 5.Min Stack(能返回最小数的栈)
Level: Easy 题目描述: Design a stack that supports push, pop, top, and retrieving the minimum element ...
- 牛客寒假算法基础集训营4 F Applese 的QQ群
链接:https://ac.nowcoder.com/acm/contest/330/F来源:牛客网 Applese 有一个QQ群.在这个群中,大家互相请教问题.如 b 向 a 请教过问题,就把 a ...
- Large Writes in Exadata FlashCache
在 Exadata存储管理软件12.2.1.1.0中,flashcache开始支持复杂排序和大量的hash join产生的临时数据写入flashcache中,而不是直接写入SAS磁盘的tempfile ...
- k-sum 问题
问题描述 给定一个数组及数字 k ,从数组中找出所有相加结果为 k 的组合. 示例: 给定数组 [1,1,1] 令 k=2,输出: [[1,1]] 给定数组 [10, 1, 2, 7, 6, 1, 5 ...