【发布时间】:2017-03-01 17:18:17
【问题描述】:
我不是经验丰富的开发人员,但我目前正在学徒,我的高级开发人员最近离开了,我一个人呆着!
他告诉我,使用“GET”请求比“POST”更好,但在阅读后我想切换到“POST”,我唯一的问题是我有点不确定如何修改我的代码以进行切换从“获取”。我在下面留下了我们系统的通用 $scope。任何帮助都会很棒
$scope.changenote=function(id,note){
note = encodeURIComponent(note);
var inserthistory = './dbscripts/solicitors/changenote.php?id=' + id + '&user=' + AppStorage.getCurrentUser().username + '¬e=' + note;
console.log(inserthistory);
$http({method: 'GET', url: inserthistory}).success(function(data) {
var historyurl = './dbscripts/solicitors/gethistory.php?ref=' + $scope.bbref;
$http({
method: 'GET',
url: historyurl
}).success(function(data) {
$scope.histnoteaddbtn = [];
$scope.history = data;
$state.go($state.current, {}, {
reload: true
});
});
swal("Saved!", "Your note has been saved!", "success")
})
}
【问题讨论】:
-
嗯,这取决于您在使用什么系统!我的意思是它是 CMS 还是...?而且您不能总是将 GET 更改为 POST !有时你需要在某些功能中使用每一个!关于安全性, POST 和 GET 基本上没有区别!在这两种情况下,您都必须使用准备好的查询语句并在查询中使用数据之前检查数据!
-
@GeomanYabes 大喊大叫?在哪里?
-
Soheyl 的评论.. :D 总是带有
! -
我不好的是看 OP 的帖子 ;)
-
它们在语义上是不同的——你可以使用
GET来获取资源(例如 id 为 26 的页面)和POST来创建资源(例如发布生成网络邮件的表单)——尽管因为 HTML 表单仅支持获取和发布,但发布的用途不止于此。如果您正在构建一个 RESTful 应用程序...:restapitutorial.com/lessons/httpmethods.html 简而言之,使用 HTML,您不希望有人能够通过在地址栏中输入内容来创建/更新/删除资源 - 所以只能使用 @ 987654326@阅读。