angularJS实现跨域请求

来源:互联网 发布:订餐源码 微信 java 编辑:程序博客网 时间:2024/06/05 22:43

一直都用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

0 0
原创粉丝点击