如何使用 $http_post AngularJS + Laravel 重定向
How to redirect with $http_post AngularJS + Laravel ?
今天早上我发现了$http_method,它太棒了!但是....我有一个问题另一个时间 XD
首先,我发送了正确的内容,并且DataBasae已正确更新,但是当我尝试使用以下代码更新站点时,我遇到了错误。
$timeout(function() {
$location.path('/');
});
我的代码是这样的
$scope.processForm = function() {
$http({
method : 'POST',
url : 'todos',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
})
};
我的文件路由中的控制器.php在 Laravel 中是下一个:
Route::post('todos', function()
{
$user = new Nodes;
$user->name = Input::get("name");
$user->save();
});
当我在表单中发送内容时,我不知道如何更新网页......对此有什么解决方案吗?
在控制器中,将$location作为服务依赖项注入,然后添加一个 then 函数,该函数确定当服务器成功响应时会发生什么
app.controller('ctrlName', ['$scope', '$location', function($scope, $location){
$scope.processForm = function() {
$http({
method : 'POST',
url : 'todos',
data : $.param($scope.formData), // pass in data as strings
headers : { 'Content-Type': 'application/x-www-form-urlencoded' } // set the headers so angular passing info as form data (not request payload)
}).then(function(response){
//successfully posted data
$location.path('/');
}, function(response){
//error has occurred
})
};
}])
相关文章:
- 我应该先学习Angularjs还是Laravel
- AngularJs和Laravel的Pretty Urls不起作用
- 如何将Laravel变量传递到我的AngularJS视图中
- laravel/angularjs JWT代币刷新
- 如何使用AngularJS和ui-router从Laravel 5.1获取下载文件
- Laravel 5和AngularJS删除'#'来自url
- 如何处理php(Laravel-api)和javascript(AngularJS)之间的日期时间
- AngularJS和Laravel CORS,POST在预检选项后停止
- Angularjs :如何用 Laravel 显示 ng-repeat 的内容
- Laravel + AngularJS CORS 不起作用
- 如何使用 $http_post AngularJS + Laravel 重定向
- 在Laravel PHP和AngularJS中维护子域之间的会话
- 如何从Laravel视图/模板目录提供单页AngularJS应用程序
- AngularJs Data fetch from Laravel
- 如何在Laravel + AngularJs上的脚本标签中读取JSON
- AngularJS从Laravel获取参数
- Laravel{!!表单::open()!}不'不在AngularJS中工作
- 从laravel向Angularjs$scope返回true或false
- Laravel+AngularJs,使用带ng-scr的基本路径,而不是当前路径
- 如何推送通知到特定用户Node + AngularJS + Laravel