一直都用Jsonp的方式来解决angularjs跨域问题,查询读取信息还可以。如果是遇到比如登陆,需要post用户信息的,这个时候必须要用到post方式。
service端配置,post数据的接口处加上下面代码:
header('Access-Control-Allow-Origin: *');
header('Access-Control-Allow-Headers: X-Requested-With');
angularjs处$http要按照下面方式写:
$http({
url:'http://www.xxx.com/index.php?app=api&ac=user&ts=login',
method:"POST",
headers: {
'Content-Type': 'application/x-www-form-urlencoded'
},
data: {
'email': 'root@qq.com','password': '123456'
}
});
转自:
http://www.360doc.com/content/16/0110/08/597197_526779124.shtml