添加了重定向后,AngularJS无法向DB发送JSON数据
AngularJS Unable to send JSON data to DB after adding redirect
我正试图将JSON数据发送到后端数据库。在使用"$window.location"将重定向添加到newPost函数之前,下面的代码可以正常工作。Href = 'success.html';"添加重定向后,不会向数据库提交任何内容。控制台中也没有显示错误。我想,我可能应该检查一下这个帖子是否成功,但我不确定如何正确地做到这一点。
app.controller('FormCtrl', function($scope, $filter, $window, getData, Post, randomString) {
// Get all posts
$scope.posts = Post.query();
// Form data for creating a new post with ng-model
$scope.postData = {};
$scope.$on('updateImage', function () {
$scope.postData.attachment = getData.image;
});
$scope.postData.userid = "Mango Farmer";
$scope.postData.uuid = randomString(32);
$scope.$on('updateGPS', function () {
$scope.postData.gps = getData.gps;
});
$scope.postData.devicedate = $filter('date')(new Date(),'yyyy-MM-dd HH:mm:ss');
$scope.newPost = function() {
var post = new Post($scope.postData);
console.log(post);
post.$save();
$window.location.href = 'success.html';
}
});
服务器响应成功
RETURN CODE: 200
RETURN HEADERS:
Content-Type: application/json
RETURN BODY:
{
"ref":<string>,
"uuid":<string>
}
post.$save();
$window.location.href = 'success.html';
应:post.$save().then(function(response) {
$window.location.href = 'success.html';
});
我很确定那是对的。试一试,让我知道。
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 如何为json对象中的段发送array[]
- 我想使用模态通过php文件发送邮件,并且我希望在提交关闭后关闭pop
- 在验证和发送邮件后更改联系人表单的 html
- 将Javascript数组发送到控制器ASP.NET MVC
- 如何将字符串值从php页面发送到java脚本页面
- 使用angularjs向浏览器发送servlet响应(下载功能)
- 如何使用Socket.io将命令从客户端发送到服务器
- MockJax没有在JavaScript应用程序中发送对我AJAX请求的响应
- 如何在react js中将值从一个组件发送到另一个组件
- 将日期时间作为 JSON 发送将无法在我的视图中正确显示
- 我的shareService在angular 2中发送值工作正常,但当我渲染我的另一个组件时,会获得默认值
- 如何将javascript事件从web浏览器wpf控件发送到wpf的c#代码
- 如何接受 html 表单中的浮点值并将其发送到 MySQL DB
- 将Javascript变量发送到PHP以保存到DB
- 可以't在使用node js将动态字段值插入mysql DB时,在发送头之后设置头
- 如何保存对象以供以后使用?通过JSON或其他方式发送并存储在DB中,然后恢复
- 添加了重定向后,AngularJS无法向DB发送JSON数据
- 麻烦发送attr int变量通过ajax,到php,到db列
- 如何将数据从inputdatetimepicker.js发送到jsp并将这些数据保存在db中