angularjs $http实现get和post请求
来源:互联网 发布:云网络验证 编辑:程序博客网 时间:2024/06/05 21:14
angularjs $http实现get和post请求
本文主要介绍如何通过angularjs的$http实现get和post请求。
好,下面上货。
首先看一下后台的服务。
package com.xueyou.demo.controller;import com.xueyou.demo.pojo.Student;import org.springframework.web.bind.annotation.CrossOrigin;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RequestMethod;import org.springframework.web.bind.annotation.RestController;import java.util.ArrayList;import java.util.List;@RestController@CrossOrigin@RequestMapping("/request")public class RequestController { @RequestMapping(value = "/get", method = {RequestMethod.GET}) public List<Student> getStudentList() { Student student = new Student(1, "xiaoming"); List<Student> studentList = new ArrayList<>(); studentList.add(student); return studentList; } @RequestMapping(value = "/post", method = {RequestMethod.POST}) public List<Student> postStudentList() { Student student = new Student(2, "xiaohong"); List<Student> studentList = new ArrayList<>(); studentList.add(student); return studentList; }}
然后是angularjs的请求:
biPlateform.controller('mainController', function ($scope, $stateParams, $http) { $scope.test = "bbb"; var c = $stateParams.id; console.log(c); $http.post(Setting.BASE_URL + "/request/post").success(function (data, status, headers, config) { console.log(data); }).error(function (data, status, headers, config) { console.error(data); }); $http.get(Setting.BASE_URL + "/request/get").success(function (data, status, headers, config) { console.log(data); }).error(function (data, status, headers, config) { console.error(data); })});
下面看一下调用之后的结果:
注意,在服务端,也就是后台程序一定要加上@CrossOrigin,否则会出现跨域问题。
阅读全文
0 0
- angularjs $http实现get和post请求
- angularJS 发起$http.post和$http.get请求
- angularJS 发起$http.post和$http.get请求
- Angularjs $http 请求数据(get.post)
- HTTP get和post请求
- http post和get请求
- c++实现http的get和post请求
- Volley框架实现Http的get和post请求
- java实现http的get和post请求
- VC实现http发送get和post请求
- Http协议(get请求和post请求)
- HTTP post请求和get请求
- HTTP的GET请求和POST请求
- HTTP请求的GET和POST请求
- HTTP的GET请求和POST请求
- C#实现http协议GET、POST请求
- C#实现http协议GET、POST请求
- C# 实现http协议GET、POST请求
- 参考coupon开发cardcoupon-2
- Hashtable的实现原理
- es6-函数
- 51Nod 独木舟
- C++网站开发MVC框架TreeFrog Framework教程——7.ERB模板
- angularjs $http实现get和post请求
- int strlen(char *p);的实现(不开辟任何空间)
- 如何在串口调试助手上,使用printf()函数显示十进制的数据及汉字说明(c语言版)
- VUE —— 结构渲染
- Python闭包、函数式编程、装饰器深入理解
- 最经济synchronized锁对象
- servlet生命周期
- 数字证书和数字签名概念小结
- 大数据时代的技术hive:hive介绍