angular 和jq 的AJAX的请求区别
|
|
Sending Data to the ServerBy default, Ajax requests are sent using the GET HTTP method. If the POST method is required, the method can be specified by setting a value for the The |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
<!DOCTYPE html><html><head> <title></title> <script src="js/jquery.js"></script> <script src="js/angular.js"></script></head><body ng-app="myApp"><div> <h1>Hello World</h1></div><div> <span>Angular ajax:</span> <a href="#" ng-controller="btnCtrl" ng-click="asave()">Button</a></div><div> <span>jQuery ajax:</span> <a href="#" id="jBtn">Button</a></div><div> <span>Angular as jQuery ajax:</span> <a href="#" ng-controller="btnCtrl" ng-click="ajsave()">Button</a></div></body><script src="js/index.js"></script></html> |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
var myApp = angular.module('myApp',[]);var btnCtrl = myApp.controller('btnCtrl',['$scope','$http',function($scope,$http){ $scope.asave = function(){ var user = { name : 'zhangsan', id : '3' } $http({method:'POST',url:'/asave',data:user}).success(function(data){ console.log(data); }) }; $scope.ajsave = function(){ var data = 'namelisi&id=4' $http({ method: 'POST', url: 'ajsave', data: data, // pass in data as strings headers: {'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'} }).success(function (data) { console.log(data); }); };}]);$('#jBtn').on('click',function(){ $.ajax({ type : 'POST', url : 'jsave', data : {name:'wangwu',id:'5'}, dataType:'json', success : function(data){ console.log(data); } })}); |



|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
|
public class User { public String name; public String id; public String getName() { return name; } public void setName(String name) { this.name = name; } public String getId() { return id; } public void setId(String id) { this.id = id; }} |
|
1
2
3
4
5
6
7
|
@RequestMapping("/asave") @ResponseBody public String asave(@RequestBody User user){ System.out.println("name---"+user.getName()); System.out.println("id---"+user.getId()); return "ok"; } |
|
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
|
@Controllerpublic class MyController { @RequestMapping("/test") @ResponseBody public String test(){ return "hello world"; } @RequestMapping("/asave") @ResponseBody public String asave(@RequestBody User user){ System.out.println("name---"+user.getName()); System.out.println("id---"+user.getId()); return "ok"; } @RequestMapping("/jsave") @ResponseBody public String jsave(@RequestParam String name, @RequestParam String id){ System.out.println("name---"+name); System.out.println("id---"+id); return "ok"; } @RequestMapping("/ajsave") @ResponseBody public String ajsave(@RequestParam String name, @RequestParam String id){ System.out.println("name---"+name); System.out.println("id---"+id); return "ok"; }} |
angular 和jq 的AJAX的请求区别的更多相关文章
- 普通B/S架构模式同步请求与AJAX异步请求区别(个人理解)
在上次面试的时候有被问到过AJAX同步与异步之间的概念问题,之前没有涉及到异步与同步的知识,所以特意脑补了一下,不是很全面... 同步请求流程:提交请求(POST/GET表单相似的提交操作)---服务 ...
- Angular和jQuery的ajax请求的差别
近期项目中使用angular,结果发现后台没法获取參数,所以,略微研究了一下两者在发送ajax时的差别. 注意angular和jquery的ajax请求是不同的. 在jquery中,官方文档解释con ...
- JQ之$.ajax()方法以及ajax跨域请求
AJAX(Asynchronous javascript AND xml :异步javascript和xml):是一种创建交互式网页应用的网页开发技术.AJAX可以在不重新加载整个页面的情况下与服务器 ...
- js中ajax连接服务器open函数的另外两个默认参数get请求和默认异步(open的post方式send函数带参数)(post请求和get请求区别:get:快、简单 post:安全,量大,不缓存)(服务器同步和异步区别:同步:等待服务器响应当中浏览器不能做别的事情)(ajax和jquery一起用的)
js中ajax连接服务器open函数的另外两个默认参数get请求和默认异步(open的post方式send函数带参数)(post请求和get请求区别:get:快.简单 post:安全,量大,不缓存)( ...
- ajax同步请求与异步请求的区别
ajax 区别: async:布尔值,用来说明请求是否为异步模式.async是很重要的,因为它是用来控制JavaScript如何执行该请求. 当设置为true时,将以异步模式发送该请求,JavaScr ...
- vue-d2admin-axios异步请求登录,先对比一下Jquery ajax, Axios, Fetch区别
先说一下对比吧 Jquery ajax, Axios, Fetch区别之我见 引言 前端技术真是一个发展飞快的领域,我三年前入职的时候只有原生XHR和Jquery ajax,我们还曾被JQuery 1 ...
- jq使用ajax请求,返回状态 canceled错误
在使用jq,ajax请求时出现该错误 原因:button按钮类型为type=submit ,script中又自定用botton按钮点击提交ajax,造成冲突. 解决方法:button按钮类型改为 ty ...
- 原生ajax异步请求基础知识
一.同步交互与异步交互的概念: * 同步交互:客户端向服务器端发送请求,到服务器端进行响应,这个过程中,用户不能做任何其他事情(只能等待响应完才能继续其他请求). * 异步交互:客户端向服务器端发送请 ...
- ajax 处理请求回来的数据
比如接口 /test, 请求方式get, 请求过来的数据要处理在container 里,如下代码 $.get("/test", {}, function(result){ $(&q ...
随机推荐
- Anti-pattern
https://en.wikipedia.org/wiki/Anti-pattern https://zh.wikipedia.org/wiki/反面模式 An anti-pattern is a c ...
- Java中同步
解决资源共享的同步操作,有两种方法:一是同步代码块,二是同步方法. 在需要同步的代码块加上synchronized关键字, 同步代码块时必须指定一个需要同步的对象,但一般都是将当前对象(this)设置 ...
- P1371 NOI元丹
luogu月赛的题 本来想爆搜,但是经过ly大佬的点拨,明白这是一个dp. 我们定义dp[n]为从n开始的可行串的数目,具体如下:如果n为'I',则是从n开始有多少个I,如果n为'O',既是从n开始有 ...
- Android源码剖析之Framework层基础版(窗口、linux、token、Binder)
本文来自http://blog.csdn.net/liuxian13183/ ,引用必须注明出处! 关于Framework,就是应用层底下的控制层,离应用层最近,总想找个机会,写写WindowMang ...
- python中的类,对象,方法,属性等介绍
注:这篇文章写得很好.加底纹的是我自己的理解 python中一切皆为对象,所谓对象:我自己就是一个对象,我玩的电脑就是对象,坐着的椅子就是对象,家里养的小狗也是一个对象...... 我们通过描述属性( ...
- 使用node.js的bodyParser中间件读取post数据解析
昨天我们使用的网关转发数据时出了点问题! 情景是这样的,另一方以Post的形式向我的node.js服务推送JSON数据.但是使用bodyParser中间件后,在req.body中拿不到任何信息. 代码 ...
- [LeetCode]题解(python):038-Count and Say
题目来源 https://leetcode.com/problems/count-and-say/ The count-and-say sequence is the sequence of inte ...
- boost.compressed_pair源码剖析
意义 当compressed_pair的某一个模板参数为一个空类的时候将对其进行“空基类优化”,这样可以使得compressed_pair占用的空间比std::pair的更小. 参考如下代码: #in ...
- windows server 2008服务器IIS绑定阿里云域名
一.打开Internet 信息服务(IIS)管理器 二.将你的网站放到服务器目录下,比如D盘下的WWW文件夹. 三.在IIS中,添加网站,网站的物理路径指向第二部中创建的网站. 五.在绑定 ...
- ubuntu网络配置
本文介绍ubuntu中的网络配置方法. ubuntu需要在/etc/network/interfaces文件中设置网络配置,基本的格式如下: auto <网卡名> iface <网卡 ...