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. server12装.NET 3.5

    参考:https://support.microsoft.com/en-us/help/2734782/net-framework-3-5-installation-error-0x800f0906- ...

  2. JBOSS在win7环境下启动run.bat无反应

    今天从隔壁机器拷贝了一份Jboss,却发现启动无任何反应. 仔细对比了jdk jboss的各项参数发现都是相同,无奈之下,检查run.bat文件 发现时在此句出现前后 无反应: "%JAVA ...

  3. Kibana error " Fielddata is disabled on text fields by default. Set fielddata=true on [publisher] ..."

    Reason of this error:Fielddata can consume a lot of heap space, especially when loading high cardina ...

  4. iOS 11 ScrollView偏移问题解决

    if (@available(iOS 11.0, *)){//避免滚动视图顶部出现20的空白以及push或者pop的时候页面有一个上移或者下移的异常动画的问题 [[UIScrollView appea ...

  5. 使用box-shadow 实现水波、音波的效果

    用到的工具 animation box-shadow html: <div class="watersource"> </div> css: .waters ...

  6. springboot整合redis存放session

    y进入maven依赖: <!--spring boot 与redis应用基本环境配置 --> <dependency> <groupId>org.springfra ...

  7. 在本地开发环境没问题,但是发布到服务器出现:未能写入输出文件“c:\Windows\Microsoft.NET\Framework64\v4.0.30319\Temporary ASP.NET Files\root\106f9ae8\cc0e1169\App_global.asax.haz99mum.dll”--“拒绝访问。 ”错误

    解决方法: 1,通常的解决方法:原因是由于系统目录下的Temp目录无相应的权限所致,具体操作如下:C:\Windows\temp-->属性-->安全-->编辑-->添加NETW ...

  8. 编译 OpenWrt/LEDE 基本过程

    说明 前段时间花 110 从闲鱼淘了个 Newifi D1,这个路由的 Soc 是 MT7621AT,性能强劲,于是又开始折腾编译固件了,重新记录一下编译基本过程. 步骤 安装必要的软件包 sudo ...

  9. 计算机学院大学生程序设计竞赛(2015’12)The collector’s puzzle

    Problem Description There is a collector who own many valuable jewels. He has a problem about how to ...

  10. jsonp跨域请求及本质

    在html页面中,能实现跨域请求的是 第一: <script src="http://localhost:59602/JsonpTest.ashx?callBack=callBack& ...