jsonp + php 跨越请求
来源:互联网 发布:网络电视机顶盒作用 编辑:程序博客网 时间:2024/04/30 10:47
$allowOrigins = array('http://my.domain1.com','http://my.domain2.com',);$clientOrigin = isset($_SERVER['HTTP_ORIGIN'])? $_SERVER['HTTP_ORIGIN'] : '';if(in_array($clientOrigin, $allowOrigins)){\Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Credentials','true');\Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Origin',$clientOrigin);\Yii::$app->getResponse()->getHeaders()->set('Access-Control-Allow-Methods','GET, POST, PUT, DELETE, OPTIONS');}
$.ajax({// The 'type' property sets the HTTP method.// A value of 'PUT' or 'DELETE' will trigger a preflight request.type: 'GET',// The URL to make the request to.url: 'http://my.domain.com',crossDomain:true,//请求偏向外域xhrFields: {// The 'xhrFields' property sets additional fields on the XMLHttpRequest.// This can be used to set the 'withCredentials' property.// Set the value to 'true' if you'd like to pass cookies to the server.// If this is enabled, your server must respond with the header// 'Access-Control-Allow-Credentials: true'.// 如果你想向服务器发送cookies的话,设置withCredentials为true// 而且你的服务器必须返回头部带有'Access-Control-Allow-Credentials: // true'的回应withCredentials: true},header: {// 在这里设置自定义的头部// Set any custom headers here.// If you set any non-simple headers, your server must include these// headers in the 'Access-Control-Allow-Headers' response header.},success: function() {// Here's where you handle a successful response.// 这里处理服务器成功返回数据的情况},error: function() {// Here's where you handle an error response.// Note that if the error was due to a CORS issue,// this function will still fire, but there won't be any additional// information about the error.// 这里处理错误的回应}});
0 0
- jsonp + php 跨越请求
- jsonp的跨越请求
- JFinal ajax 跨越请求 jsonp
- 同源策略、跨越请求和JSONP
- 同源策略、跨越请求和JSONP
- php Jsonp 跨域 请求
- php jsonp跨域请求
- php jsonp跨域请求
- 跨越请求
- java 跨越访问 (jquery,jsonp)
- JSONP跨越不理解的地方
- ajax+jsonp+php 实现跨域请求
- php 中jsonp跨域请求
- PHP AJAX JSONP实现跨域请求
- Jsonp请求
- 利用jsonp实现跨越获取数据
- jsonp实现跨越js调用的原理
- PHP跨越调用接口
- 我身边幽默风趣的程序猿
- 漫步凸分析二——凸集和锥
- 网络下载图片
- Android中使用Handler造成内存泄露的分析和解决
- POJ-1276-Cash Machine
- jsonp + php 跨越请求
- Android开源项目推荐之「图片加载到底哪家强」
- git实战
- 比例尺/空间分辨率
- 直方图均衡化
- 杨辉三角形
- C语言中函数参数入栈顺序_2015.10.28
- Grails 文件上传
- 二十种特征变换方法及Spark MLlib调用实例(Scala/Java/python)(一)