function test(){
$.ajax({
//提交数据的类型 POST GET
type:"POST",
//提交的网址
url:"testLogin.aspx",
//提交的数据 该参数为属性值类型的参数
//(和url?Name="sanmao"&Password="sanmapword"一样)后台若为SpringMVC接受,注明@RequestParam
data:{Name:"sanmao",Password:"sanmaoword"},
//返回数据的格式
datatype: "html",//"xml", "html", "script", "json", "jsonp", "text".
//在请求之前调用的函数
beforeSend:function(){$("#msg").html("logining");},
//成功返回之后调用的函数
success:function(data){
$("#msg").html(decodeURI(data));
} ,
//调用执行后调用的函数
complete: function(XMLHttpRequest, textStatus){
alert(XMLHttpRequest.responseText);
alert(textStatus);
//HideLoading();
},
//调用出错执行的函数
error: function(){
//请求出错处理
}
}); }

若要提交json格式的参数:

$(function(){
//隐藏警告信息
$(".alert-warning").hide(); $("#dependentName").blur(function(){ $.ajax({
//提交数据的类型 POST GET
type:"POST",
//提交的网址
url:"${path}/dependentOffice/checkName",
//提交的数据
data: JSON.stringify(GetJsonData()),
           //参数格式为json
contentType: "application/json; charset=utf-8",
//返回数据的格式
datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
//成功返回之后调用的函数
success:function(data){
alert(data);
},
//调用出错执行的函数
error: function(){
//请求出错处理
alert("请求失败");
} }); });

//json格式的数据源
function GetJsonData() {
var json = {
"userName": 'Tom',
"tel": '10086'
};
return
json;
}

});

后台接受需注明@RequestBody,在就需加入jackson的jar

@RequestMapping("/checkName")
@ResponseBody
public String checkName(@RequestBody User user ) {
//Integer id = dependentOfficeService.selectDependentOfficeByName(dependentName); return user.toString();
}

jquery ajax post请求实例的更多相关文章

  1. jquery Ajax请求示例,jquery Ajax基本请求方法示例

    jquery Ajax请求示例,jquery Ajax基本请求方法示例 ================================ ©Copyright 蕃薯耀 2018年5月7日 https: ...

  2. jquery Ajax异步请求之session

    写了一个脚本,如下: $(function () { $("#btnVcode").click(function () { var receiveMobile = $(" ...

  3. jQuery Ajax(异步请求)

    jQuery异步请求 原始的异步请求是需要创建的 XMLHttpRequest 对象.(IE5,6不支持)目前很多浏览器都支持XMLHttpRequest对象 jQuery ajax常用的回调函数:b ...

  4. JQuery Ajax 发送请求成功后却接收不到任何响应数据问题

    问题描述 使用 JQuery Ajax 向后端服务器发送请求,服务器也收到请求返回了响应数据,但是 Ajax 却收不到任何响应数据. 举例如下: $.ajax({ type: "post&q ...

  5. ajax异步请求实例

    1. 问题分析 用户管理显示页面:usermanagement.tpl(也可以说是MVC中的V,即视图) 用户管理数据发送页面:usermanagement.php(也可以说是MVC中的M,即模型) ...

  6. jQuery ajax - getJSON() 用法实例

    实例 从 test.js 载入 JSON 数据并显示 JSON 数据中一个 name 字段数据: $.getJSON("test.js", function(json){ aler ...

  7. jquery ajax异步请求

    得先知道后台接口给ajax访问(接口URl和传入接口的参数及参数类型),知道访问之后返回的数据类型,有哪些数据.   选择异步请求的方式,常用的有三种,如$.ajax().$.post().$.get ...

  8. JQuery Ajax 设置请求头信息application/json

    今天有个api后台接application/json格式的 在Jquery里$.ajax默认是contentType: application/x-www-form-urlencoded; chars ...

  9. jquery ajax/post 请求 案例

    @RequestMapping("/hello")    @ResponseBody    public Hello getJson(HttpServletRequest requ ...

随机推荐

  1. 【Codeforces Round #501 (Div. 3)】

    A:https://www.cnblogs.com/myx12345/p/9842904.html B:https://www.cnblogs.com/myx12345/p/9842964.html ...

  2. BZOJ1583: [Usaco2009 Mar]Moon Mooing 哞哞叫

    给n<=4000000,c,a1,b1,c1,a2,b2,c2,以c为初始得到的数,每次可以把得到的某个数x进行操作f1(x)=a1*x/c1+b1,f2(x)=a2*x/c2+b2,求最后能得 ...

  3. 【zTree】zTree根据后台数据生成树并动态设置前面的节点复选框的选中状态

    0.页面中准备树的ul <ul id="treeDemo10" class="ztree" style="display: none;" ...

  4. 没啥用,更换注册表信息使webbrower选择适合的版本

    /// <summary>            /// 修改注册表信息来兼容当前程序            ///             /// </summary>   ...

  5. loj517 计算几何瞎暴力(Trie树)

    题目: https://loj.ac/problem/517 分析: 操作4比较特殊,我们先来分析下操作4 操作4相当于需要一个数据结构,使得里面的数据有序(这有很多选择) 结合操作1,操作4的“排序 ...

  6. MySQLWorkbench里的稀奇事之timestamp的非空默认值

    在创建表时,某字段为非空时间戳,timestamp not null 问题来了,使用workbench建表时,如果值非空,是需要有一个默认值的,不然会报错. 那么,如果是更新时自动填充可以使用DEFA ...

  7. HttpUtils 用于进行网络请求的工具类

    原文:http://www.open-open.com/code/view/1437537162631 import java.io.BufferedReader; import java.io.By ...

  8. 集群FULL GC导致服务不可用

    FULL GC会导致stop-the-world,频繁的FULL GC会影响系统的可用性.stackoverflow上有个提问是这么描述这个问题的:当服务器集群批量启动后,执行FULL GC的频率和时 ...

  9. [RxJS] Chain RxJS Operators Together with a Custom `pipe` Function using Array.reduce

    Instead of writing complex operators, it's usually best to write simple, single-purpose operators th ...

  10. Guice 学习(八)AOP (面向切面的编程)

    Guice的AOP还是非常弱的.眼下只支持方法级别上的,另外灵活性也不是非常高. 看例如以下演示样例: Guice支持AOP的条件是: 类必须是public或者package (default) 类不 ...