Angular和jQuery的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和jQuery的ajax请求的差别的更多相关文章
- jQuery发送ajax请求
利用jquery发送ajax请求的几个模板代码. $.ajax({ async : false, type: 'POST', dataType : "json", url: &qu ...
- JQuery发送ajax请求不能用数组作为参数
JQuery发送ajax请求不能用数组作为参数,否则会接收不到参数, 一.js代码如下: $('#delete-button').click(function(){ var select ...
- Jquery发送ajax请求以及datatype参数为text/JSON方式
Jquery发送ajax请求以及datatype参数为text/JSON方式 1.方式一:datatype:'text' 2.方式二:datatype:'JSON' 3.使用gson-1.5.jar包 ...
- 使用es6的then()方法封装jquery的ajax请求
使用场景: jsp页面中使用jquery的ajax请求比较频繁,以前vue框架的项目用过axios,所以就想着用then()封装一个公共请求的方法,这样每次请求就不用那么麻烦的写一大堆请求参数了. 示 ...
- 如何终止JQUERY的$.AJAX请求
最近遇到,如果用户频繁点击ajax请求,有两个问题: 1,如果连续点击了5个ajax请求,前4个其实是无效的,趁早结束节省资源. 2,更严重的问题是:最后一个发送的请求,响应未必是最后一个,有可能造成 ...
- jquery中ajax请求后台数据成功后既不执行success也不执行error解决方法
jquery中ajax请求后台数据成功后既不执行success也不执行error,此外系统报错:Uncaught SyntaxError: Unexpected identifier at Objec ...
- jQuery发送Ajax请求以及出现的问题
普通jQuery的Ajax请求代码如下: $.ajax({ type: 'POST', url: "http://xxx/yyy/zzz/sendVerifyCode", data ...
- Sping MVC不使用任何注解处理(jQuery)Ajax请求(基于XML配置)
1. Spring Spring框架是一个轻量级的解决方案,是一个潜在的一站式商店,用于构建企业就绪的应用程序.Spring框架是一个Java平台,为开发Java应用程序提供全面的基础架构支持.Spr ...
- Struts2处理(jQuery)Ajax请求
1. Ajax Ajax(Asynchronous JavaScript and XML,异步JavaScript和XML)时一种创建交互式网页应用的网页开发技术,它并不是一项新的技术,其产生 ...
随机推荐
- SQL Union和SQL Union All用法
SQL UNION 操作符 UNION 操作符用于合并两个或多个 SELECT 语句的结果集. 请注意,UNION 内部的 SELECT 语句必须拥有相同数量的列.列也必须拥有相似的数据类型.同时,每 ...
- POJ 3274 Gold Balanced Lineup(哈希)
http://poj.org/problem?id=3274 题意 :农夫约翰的n(1 <= N <= 100000)头奶牛,有很多相同之处,约翰已经将每一头奶牛的不同之处,归纳成了K种特 ...
- 服务器部署_centos 安装jdk手记
1. 下载jdk略. 2. 将jdk相关文件目录放到指定目录 (1) 创建jdk目录 /usr/java/jdk7 mkdir -p /usr/java/jdk7 (2) 解压缩jdk压缩包,并移动至 ...
- MySQL can’t specify target table for update in FROM clause
翻译:MySQL不能指定更新的目标表在FROM子句 源SQL语句: delete from t_official_sys_user where USER_NAME IN(SELECT USER_NAM ...
- [Quick-x]制作新手引导高亮区域方法之二:裁剪模式
demo下载:https://github.com/chenquanjun/Quick-x-HighlightArea 2.裁剪模式 (1)创建裁剪对象 , , ) --非高亮区域颜色 local b ...
- 【HDOJ】1241 Oil Deposits
经典的BFS. #include <stdio.h> #include <string.h> #define MAXNUM 105 #define MAXROW 105 #de ...
- Java金字塔及变形
Java金字塔 package com.tfj.test; public class JinZiTa { public static void main(String[] args){ int num ...
- Linux -- Ubuntu搭建java开发环境
Steps 1 Check to see if your Ubuntu Linux operating system architecture is 32-bit or 64-bit, open up ...
- rebuild过程
/** The class defining a handle to an Innodb table */ class ha_innobase: public handler { row_prebui ...
- Aspcms所有标签调用
错误号3002: 出现此问题一般是有些频道模板不全,或者缺少一部分模板导致,或者没有单独设置html文件夹,并将所有html页面放进去 基本语法 {aspcms:sitepath} 网站终极目录(可放 ...