如果不设置头部的话,post请求自动变成了options请求,真坑
所以,post请求的时候,需要配置一下header
var req = {
method: 'POST',
url: url,//url 请求的地址
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8',
'Accept': '*/*'
},
data:str //str 必须是a=b&c=d的格式 get请求得数据
};
$http(req).success(function(data, status, headers, config){
console.log("success",data, status, headers, JSON.stringify(config));
}).error(function(data, status, headers, config){
console.log("error",data, status, headers, JSON.stringify(config));
});
}
这样,app请求数据,就不会提示为options的请求了