当前位置

网站首页> 程序设计 > 开源项目 > 程序开发 > 浏览文章

angular学习采坑记录 - 谦龙的学习笔记

作者:小梦 来源: 网络 时间: 2024-03-23 阅读:

前言

最近实习工作中即将开始的一个项目中要使用到angular.js,之前虽然有一定的了解,但是缺少实践机会,现在把学习过程中可能遇到的坑记录下来,希望回头再看会有更多收获

$http post方式提交请求遇

问题说明

使用$http模块向本地服务器发送请求时发现post方式不能正常获取数据,使用get方式却可以正确获取

get方式

        var app = angular.module('myApp',[]);        app.controller('ctl',function ($scope,$http) {$http({  method : 'get',  url : 'http://127.0.0.1/simpleMessageBoard/lyb/actions/doMessage.php',  params:{'args':'get'} }).success(function (res) {    $scope.data = res;})        })

post方式(最后解决方式)

     var app = angular.module('myApp',[]);        app.controller('ctl',function ($scope,$http) {$http({  method : 'post',  url : 'http://127.0.0.1/simpleMessageBoard/lyb/actions/doMessage.php',  data:'args='+'get',  headers: {'Content-Type': 'application/x-www-form-urlencoded'}}).success(function (res) {    $scope.data = res;})        }) 

原理参照文章
参照1
参照2

网友最爱