在使用angular 请求后台api的时候,使用post方式请求会有一些问题。
这是一个标准的表单和angular $http请求后台api的例子
index.html
Username
Password
Submit
app.js
module.exports = ($scope, $http, config) => {
$scope.isValid = false;
$scope.submitForm = ( isValid ) => {
// 验证通过
if ( isValid ) {
// 提交表单 之后禁用按钮 防止重复提交
$scope.isValid = true;
let promise = $http ({
method: 'post',
url: config.api.supplier,
data: $scope.form
})
promise.then( ( res ) => {
console.log('success')
console.log( res )
}, ( res ) => {
console.log('error')
console.log( res )
<