$.ajax({
url: api.regist,
type: 'POST',
dataType: 'json',
data: {
email: $scope.email,
password: $scope.password
}
})
$http({
url: api.regist,
method: 'POST',
headers: {
'Content-Type': 'application/json'
},
data: {
email: $scope.email,
password: $scope.password
}
})
这两个不应该是完全一样的意义嘛?为什么使用 ajax 可以执行成功,但是使用 $http 就提示跨域了呢?
为情所困2017-05-15 17:02:18
postCfg = {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
},
transformRequest: function(data) {
return $.param(data);
}
}
app.config([
'$httpProvider',
function($httpProvider) {
$httpProvider.defaults.useXDomain = true;
delete $httpProvider.defaults.headers.common['X-Requested-With'];
}
]}
$http.post(url, {}, postCfg)
The method I found, the speed test was successful
滿天的星座2017-05-15 17:02:18
Angular uses jsonp cross-domain, of course, the premise is that your server returns jsonp format.
$http.jsop(url).success(fn).error(fn);