What do the url and data parts mean? How should I modify it
.directive('ensureUnique', function ($http) {
return {
require: 'ngModel',
link: function (scope, elem, attrs, ctrl) {
scope.$watch(attrs.ngModel,function(){
$http({method:'POST',
url:'/api/check/'+attrs.ensureUnique,
data:{field:attrs.ensureUnique,valud:scope.ngModel}
}).success(function(data,status,header,cfg){
ctrl.$setValidity('unique',data.isUnique);
}).error(function(data,status,header,cfg){
ctrl.$setValidity('unique',false);
})
})
}
}
})
PHP中文网2017-05-15 16:59:50
It depends on how your post interacts with the server.
The basic principle is to post the data you need, that is, the data part, to the server. On the server, you check whether the uploaded data is legal and whether it indicates that the user already exists, and then return a data structure, such as json, etc. In the success function, the returned data will be stored in the data parameter, and the final judgment is completed by checking the data in data.