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");
 $.post("/user/CheckUserName", { userName: userName }, function (result) { alert(result) }, "text");

点击提交:

这里设置了请求的格式为"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. 正经学C#_循环[do while,while,for]:[c#入门经典]

    在c#中循环语句总共三种,do...while ,while,for这三种语句. 循环语句,是为了解决一些繁琐的计算.比如输出0-10这10个数字. 在不循环的情况下你可以能这么写 Console.W ...

  2. forEach,for in,for of循环的用法

    一.一般的遍历数组的方法: var array = [1,2,3,4,5,6,7]; for (var i = 0; i < array.length; i) { console.log(i,a ...

  3. HDU - 1166 敌兵布阵 方法一:(线段树+单点修改,区间查询和) 方法二:利用树状数组

    C国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了.A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况.由于 ...

  4. 洛谷P2709 BZOJ 3781 小B的询问 (莫队)

    题目描述 小B有一个序列,包含N个1~K之间的整数.他一共有M个询问,每个询问给定一个区间[L..R],求Sigma(c(i)^2)的值,其中i的值从1到K,其中c(i)表示数字i在[L..R]中的重 ...

  5. linux中sigsuspend和pause的区别

    pause和sigsuspend都是用于等待信号的发生 简单的说,sigsuspend = unblock + pause sigsuspend 函数是用于需要先接触 某个信号的阻塞状态 然后等待该信 ...

  6. python 批量下载 spring 的 xsd

    #coding=utf-8 import os import urllib import urllib2 import re from bs4 import BeautifulSoup # 利用 ur ...

  7. 自定义Razor 标签

    1.首先需要一个abstract class WebViewPage<T> ,继承系统的 System.Web.Mvc.WebViewPage<TModel> 再定义一个Web ...

  8. Go语言基础之8--面向对象编程1之结构体(struct)

    一.结构体详解 1.1 声明和定义 1.Go中面向对象是通过struct来实现的, struct是用户自定义的类型 2.Go 语言中数组可以存储同一类型的数据,但在结构体中我们可以为不同项定义不同的数 ...

  9. tp5分组查询

    $data=DB::name('goods_common')->alias('a')->join('all580_goods_attractions w','a.common_id = w ...

  10. java thread start到run:C++源码分析

    转:https://hunterzhao.io/post/2018/06/11/hotspot-explore-inside-java-thread-run/ 整体流程 java new Thread ...