预加载器在$http.Post(多步骤表单)
Preloader on $http.post (multi-step form)
我在表单中提供预加载器时有问题。我遵循本教程在我的laravel项目中创建了一个多步骤表单。
这是我的基本表单。html:
<form id="appointment-form" name="appointmentform" ng-submit="processForm(appointmentform.$valid)">
<!-- our nested state views will be injected here -->
<div id="form-views" ui-view></div>
</form>
我的第一步表单是form.license.html:
<!-- form-license.html -->
<label>Nummerplaat ingeven</label>
<div class="form-group">
<div class="col-xs-8 col-xs-offset-2">
<input required type="text" class="form-control" name="license" ng-model="formData.license">
</div>
</div>
<div class="form-group row">
<div class="col-xs-4 col-xs-offset-4">
<a ng-click="next(1)" ui-sref="form.profile" ng-disabled="!licenseValidated" class="btn btn-next btn-block">
Volgende
</a>
</div>
</div>
在我的控制器中,我有以下内容:
$scope.next = function(step){
if(step == 1) // licensePlate
{
// receive customer data
$http.post('/api/licenseplate', { license: $scope.formData.license })
.success(function(data, status, headers, config){
var item = data.item;
console.log(item);
if(item) // fill in the name, address, email and telephone number
{
$scope.formData.profile.name = item.owner_name;
$scope.formData.profile.street = item.owner_street;
$scope.formData.profile.zipcode = item.owner_zipcode;
$scope.formData.profile.city = item.owner_city;
$scope.formData.profile.email = item.owner_email[0];
$scope.formData.profile.telephone = item.owner_tel_no[0];
}
})
.error(function(data, status, headers, config) {
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
}
else if(step == 2)
{
// save customer data
// get calendar appointments
var current_date = (m+1) + '/' + d + '/' + y;
$http.post('/api/calendar', { date: current_date })
.success(function(data, status, headers, config){
console.log(data);
var item = data.items.item;
item.sort(function(a, b) {
return a.column_id - b.column_id;
});
$scope.calendarData.pop();
$scope.calendarData.push(item);
})
.error(function(data, status, headers, config) {
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
}
};
// function to process the form
$scope.processForm = function(isValid) {
var appointment_date = $scope.formData.appointment_date;
var appointment_hour = $scope.formData.appointment_hour;
var column_id = $scope.formData.column_id;
var profile = $scope.formData.profile;
$http.post('/api/agendainsert', { appointment_datetime: appointment_date + appointment_hour, profile: profile, column_id: column_id })
.success(function(data, status, headers, config){
$location.path('/form/success/');
})
.error(function(data, status, headers, config) {
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
};
正如你所看到的,当step等于1时,我制作了一个$http.post
。现在,当我单击next时,第二个表单直接加载。在只想去第二种形式,如果http。文章已成功加载。
我试过用一些angularjs预加载器库($http)这样做,但没有任何效果。有人能给我举个例子吗?
您可以从控制器重定向到状态form.profile
:
<div class="col-xs-4 col-xs-offset-4">
<button ng-click="next(1)" ng-disabled="!licenseValidated" class="btn btn-next btn-block">
Volgende
</button>
</div>
和in控制器
$scope.next = function(step){
if(step == 1) // licensePlate
{
// receive customer data
$http.post('/api/licenseplate', { license: $scope.formData.license })
.success(function(data, status, headers, config){
var item = data.item;
if(item) // fill in the name, address, email and telephone number
{
$scope.formData.profile.name = item.owner_name;
$scope.formData.profile.street = item.owner_street;
$scope.formData.profile.zipcode = item.owner_zipcode;
$scope.formData.profile.city = item.owner_city;
$scope.formData.profile.email = item.owner_email[0];
$scope.formData.profile.telephone = item.owner_tel_no[0];
}
// go to form.profile
$state.go('form.profile');
})
.error(function(data, status, headers, config) {
console.log("Data: " + data +
"<hr />status: " + status +
"<hr />headers: " + headers +
"<hr />config: " + config);
});
}
else {
...
}
}
相关文章:
- 如何使用WCF服务和javascript表单post上传.doc文件
- 试图在表单post之后使用jQuery.post()重定向用户
- 如何将CSS和HTML元素呈现回客户端's浏览器从表单POST帐户和JavaScript
- 防止表单 POST 重定向发生,但仍保留引导验证
- 节点 Js 请求发布不将表单 POST 数据发送到 LAMP 服务器
- 通过AJAX在简单表单POST上收到500错误 - 不确定出了什么问题
- 将 Rails 表单 POST 数据传递给 JS 点击事件
- 提交 JQuery 表单 $.post() 处理成功时的显示消息
- 使用ajax/jquery模拟html表单POST
- X-editable with ASP MVC View,如何将提交的表单POST操作获取到控制器
- 无法在表单POST中调用.js
- angularjs表单post(使用ngUpload上传文件)和nodejs服务器的跨域问题
- 动态表单Post无法在mozilla中工作
- 表单POST未显示在控制器中
- Javascript防止表单post,如果没有验证
- 表单Post数据使用Ajax和jquery
- 用MVC表单Post发送HTML字符串
- 动态地向表单post添加数据
- 我如何从jQuery .submit()事件对象访问表单POST数据
- 提交带有一些附加参数的表单(post,而不是ajax)