Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法

前端之家收集整理的这篇文章主要介绍了Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

同源是指相同的协议、域名、端口,三者都相同才属于同域。不符合上述定义的请求,则称为跨域。

相信每个开发人员都曾遇到过跨域请求的情况,虽然情况不一样,但问题的本质都可以归为浏览器出于安全考虑下的同源策略的限制。

跨域的情形有很多,最常见的有Ajax跨域、Socket跨域和Canvas跨域。下面列举一些我们常见的跨域情形下,某些浏览器控制台给出的错误提示

FireFox下的提示

已阻止交叉源请求:同源策略不允许读取***上的远程资源。可以将资源移动到相同的域名上或者启用 CORS 来解决这个问题。

Canvas跨域Chrome下的提示

UncaughtSecurityError:Failed to execute'getImageData' on 'CanvasRenderingContext2D':The canvas has been taintedby cross-origin data.

或:

Imagefrom origin 'http://js.xx.com' has been blocked from loading by Cross-OriginResource Sharing policy: No 'Access-Control-Allow-Origin' header is present onthe requested resource. Origin 'http://act.xx.com' is therefore not allowedaccess.


网上有许多解决跨域的方法,大体上有这几种:

1)document.domain+iframe的设置

2)动态创建script

3)利用iframe和location.hash

4)window.name实现的跨域数据传输

5)使用HTML5 postMessage

6)利用flash

7)通过代理,js访问代理,代理转到不同的域

http://developer.yahoo.com/javascript/howto-proxy.html

8)jQuery JSONP(不能成为真正的Ajax,本质上仍是动态创建script)

http://www.cnblogs.com/chopper/archive/2012/03/24/2403945.html

9)跨域资源共享(CORS) 这是HTML5跨域问题的标准解决方

说明:方案1~方案6见Rain Man所写的文章JavaScript跨域总结与解决办法》

http://www.cnblogs.com/rainman/archive/2011/02/20/1959325.html

下面主要就我总结的几种解决跨域的方法,展开说一下。

1) 绕开跨域。

适用情形是:动静分离。

example1.com域名下的页面中跨域请求是以JavaScript内联方式实现的,而请求的目标静态资源是放在example2.com域名下,这时可以将执行跨域请求的JavaScript代码块独立出来,放到example2.com上,而example1.com页面通过外联方式引入该静态域名下的js文件。这样,js与请求的图片等资源都在example2.com下,即可正常访问到。这种方法其实是一种巧妙避开跨域的方法

2) 后台抓取克隆图片

适用情形:动静不分离(两个域名均运行访问静态资源)。

example1.com请求example2.com下的资源图片,可以使用PHP抓取图片并在example2.com下生成一份,这样就可以间接访问到example1.com的静态资源。

html模板示例代码

$("#scratchpad").wScratchPad({ //刮刮卡示例,当前域名http://act.xxx.com

width:283,

height:154,

//color: "#a9a9a7",

image2:"imgdata.PHP?url=http://js.xxx.com/static/activity/sq/guagua315/images/card_inner.jpg",

scratchMove:function() {

}

});

或:

xi=newXMLHttpRequest();

xi.open("GET","imgdata.PHP?url="+yourImageURL,true);

xi.send();

xi.onreadystatechange=function() {

if(xi.readyState==4 && xi.status==200) {

img=newImage;

img.onload=function(){

ctx.drawImage(img, 0,0,canvas.width,canvas.height);

}

img.src=xi.responseText;

}

PHP处理代码

<?PHP//imgdata.PHP

$url=$_GET['url'];

$img =file_get_contents($url);

$imgname = substr(strrchr($url,"/"),1);

file_put_contents($fn,$img);

echo $imgname;

?>

上述代码在当前PHP目录下生成了克隆生成了一张图片

3) 后台程序设置Access-Control-Allow-Origin

适用情形:Ajax获取跨域接口的JSON数据。

example1.com请求example2.com的数据接口,则需要在example2.com的数据接口添加跨域访问授权。

PHP程序中开始出添加header('HeaderName:HeaderValue'); 这样的header标记

header('Access-Control-Allow-Origin:*');

4)修改服务器配置启用CORS

适用情形:跨域访问静态资源。

Access-Control-Allow-Origin是什么作用呢?用于授权资源的跨站访问。比如,静态资源图片都放在example2.com 域名下,如果在返回的头中没有设置 Access-Control-Allow-Origin,那么别的域是没有权限外链你的图片的。

要实现CORS跨域,服务端需要这个一个流程,图片引自html5rocks,附图如下

a.对于简单请求,如GET,只需要在HTTP Response后添加Access-Control-Allow-Origin。

b.对于非简单请求,比如POST、PUT、DELETE等,浏览器会分两次应答。第一次preflight(method: OPTIONS),主要验证来源是否合法,并返回允许的Header等。第二次才是真正的HTTP应答。所以服务器必须处理OPTIONS应答。

这里是一个Nginx启用CORS的参考配置示例http://enable-cors.org/server_nginx.html代码

[plain] view plain @H_502_212@ copy @H_502_212@
  1. @H_502_212@@H_502_212@#
  2. @H_502_212@#ACORS(Cross-OriginResouceSharing)configforNginx
  3. @H_502_212@#
  4. @H_502_212@#==Purpose
  5. @H_502_212@#
  6. @H_502_212@#ThisNginxconfigurationenablesCORSrequestsinthefollowingway:
  7. @H_502_212@#-enablesCORSjustfororiginsonawhitelistspecifiedbyaregularexpression
  8. @H_502_212@#-CORSpreflightrequest(OPTIONS)arerespondedimmediately
  9. @H_502_212@#-Access-Control-Allow-Credentials=trueforGETandPOSTrequests
  10. @H_502_212@#-Access-Control-Max-Age=20days,tominimizerepetitiveOPTIONSrequests
  11. @H_502_212@#-varIoUssuperluoussettingstoaccommodatenonconformantbrowsers
  12. @H_502_212@#
  13. @H_502_212@#==CommentonechoingAccess-Control-Allow-Origin
  14. @H_502_212@#
  15. @H_502_212@#HowdoyouallowCORSrequestsonlyfromcertaindomains?Thelast
  16. @H_502_212@#publishedW3Ccandidaterecommendationstatesthatthe
  17. @H_502_212@#Access-Control-Allow-Originheadercanincludealistoforigins.
  18. @H_502_212@#(See:http://www.w3.org/TR/2013/CR-cors-20130129/#access-control-allow-origin-response-header)
  19. @H_502_212@#However,browsersdonotsupportthiswellanditlikelywillbe
  20. @H_502_212@#droppedfromthespec(see,http://www.rfc-editor.org/errata_search.PHP?rfc=6454&eid=3249).
  21. @H_502_212@#
  22. @H_502_212@#Theusualworkaroundisfortheservertokeepawhitelistof
  23. @H_502_212@#acceptableorigins(asaregularexpression),matchtherequest's
  24. @H_502_212@#Originheaderagainstthelist,andechobackthematchedvalue.
  25. @H_502_212@#
  26. @H_502_212@#(Yesyoucanuse'*'toacceptalloriginsbutthisistooopenand
  27. @H_502_212@#preventsusing'Access-Control-Allow-Credentials:true',whichis
  28. @H_502_212@#neededforHTTPBasicAccessauthentication.)
  29. @H_502_212@#
  30. @H_502_212@#==Commentonspec
  31. @H_502_212@#
  32. @H_502_212@#CommentsbelowareallbasedonmyreadingoftheCORSSpecasof
  33. @H_502_212@#2013-Jan-29(http://www.w3.org/TR/2013/CR-cors-20130129/),the
  34. @H_502_212@#XMLHttpRequestspec(
  35. @H_502_212@#http://www.w3.org/TR/2012/WD-XMLHttpRequest-20121206/),and
  36. @H_502_212@#experimentationwithlatestversionsofFirefox,Chrome,Safariat
  37. @H_502_212@#thatpointintime.
  38. @H_502_212@#
  39. @H_502_212@#==Changelog
  40. @H_502_212@#
  41. @H_502_212@#sharedat:https://gist.github.com/algal/5480916
  42. @H_502_212@#basedon:https://gist.github.com/alexjs/4165271
  43. @H_502_212@#
  44. @H_502_212@
  45. @H_502_212@location/{
  46. @H_502_212@
  47. @H_502_212@#iftherequestincludedanOrigin:headerwithanoriginonthewhitelist,
  48. @H_502_212@#thenitissomekindofCORSrequest.
  49. @H_502_212@
  50. @H_502_212@#specifically,thisexampleallowCORSrequestsfrom
  51. @H_502_212@#scheme:httporhttps
  52. @H_502_212@#authority:anyauthorityendingin".mckinsey.com"
  53. @H_502_212@#port:nothing,or:
  54. @H_502_212@if($http_origin~*(https?://[^/]*\.mckinsey\.com(:[0-9]+)?)$){
  55. @H_502_212@set$cors"true";
  56. @H_502_212@}
  57. @H_502_212@
  58. @H_502_212@#Nginxdoesn'tsupportnestedIfstatements,soweusestring
  59. @H_502_212@#concatenationtocreateaflagforcompoundconditions
  60. @H_502_212@
  61. @H_502_212@#OPTIONSindicatesaCORSpre-flightrequest
  62. @H_502_212@if($request_method='OPTIONS'){
  63. @H_502_212@set$cors"${cors}options";
  64. @H_502_212@}
  65. @H_502_212@
  66. @H_502_212@#non-OPTIONSindicatesanormalCORSrequest
  67. @H_502_212@if($request_method='GET'){
  68. @H_502_212@set$cors"${cors}get";
  69. @H_502_212@}
  70. @H_502_212@if($request_method='POST'){
  71. @H_502_212@set$cors"${cors}post";
  72. @H_502_212@}
  73. @H_502_212@
  74. @H_502_212@#ifit'saGETorPOST,setthestandardCORSresponsesheader
  75. @H_502_212@if($cors="trueget"){
  76. @H_502_212@#Tellsthebrowserthisoriginmaymakecross-originrequests
  77. @H_502_212@#(Here,weechotherequestingorigin,whichmatchedthewhitelist.)
  78. @H_502_212@add_header'Access-Control-Allow-Origin'"$http_origin";
  79. @H_502_212@#Tellsthebrowseritmayshowtheresponse,whenXmlHttpRequest.withCredentials=true.
  80. @H_502_212@add_header'Access-Control-Allow-Credentials''true';
  81. @H_502_212@##TellthebrowserwhichresponseheaderstheJScansee,besidesthe"simpleresponseheaders"
  82. @H_502_212@#add_header'Access-Control-Expose-Headers''myresponseheader';
  83. @H_502_212@}
  84. @H_502_212@
  85. @H_502_212@if($cors="truepost"){
  86. @H_502_212@#Tellsthebrowserthisoriginmaymakecross-originrequests
  87. @H_502_212@#(Here,besidesthe"simpleresponseheaders"
  88. @H_502_212@#add_header'Access-Control-Expose-Headers''myresponseheader';
  89. @H_502_212@}
  90. @H_502_212@
  91. @H_502_212@#ifit'sOPTIONS,thenit'saCORSpreflightrequestsorespondimmediatelywithnoresponsebody
  92. @H_502_212@if($cors="trueoptions"){
  93. @H_502_212@#Tellsthebrowserthisoriginmaymakecross-originrequests
  94. @H_502_212@#(Here,whichmatchedthewhitelist.)
  95. @H_502_212@add_header'Access-Control-Allow-Origin'"$http_origin";
  96. @H_502_212@#inapreflightresponse,tellsbrowserthesubsequentactualrequestcanincludeusercredentials(e.g.,cookies)
  97. @H_502_212@add_header'Access-Control-Allow-Credentials''true';
  98. @H_502_212@
  99. @H_502_212@#
  100. @H_502_212@#Returnspecialpreflightinfo
  101. @H_502_212@#
  102. @H_502_212@
  103. @H_502_212@#Tellbrowsertocachethispre-flightinfofor20days
  104. @H_502_212@add_header'Access-Control-Max-Age'1728000;
  105. @H_502_212@
  106. @H_502_212@#TellbrowserwerespondtoGET,POST,OPTIONSinnormalCORSrequests.
  107. @H_502_212@#
  108. @H_502_212@#Notofficiallyneededbutstillincludedtohelpnon-conformingbrowsers.
  109. @H_502_212@#
  110. @H_502_212@#OPTIONSshouldnotbeneededhere,sincethefieldisused
  111. @H_502_212@#toindicatemethodsallowedfor"actualrequest"notthe
  112. @H_502_212@#preflightrequest.
  113. @H_502_212@#
  114. @H_502_212@#GET,POSTalsoshouldnotbeneeded,sincethe"simple
  115. @H_502_212@#methods"GET,HEADareincludedbydefault.
  116. @H_502_212@#
  117. @H_502_212@#Weshouldonlyneedthisheaderfornon-simplerequests
  118. @H_502_212@#methods(e.g.,DELETE),orcustomrequestmethods(e.g.,XMODIFY)
  119. @H_502_212@add_header'Access-Control-Allow-Methods''GET,OPTIONS';
  120. @H_502_212@
  121. @H_502_212@#Tellbrowserweaccepttheseheadersintheactualrequest
  122. @H_502_212@#
  123. @H_502_212@#Adynamic,wide-openconfigwouldjustechobackalltheheaders
  124. @H_502_212@#listedinthepreflightrequest's
  125. @H_502_212@#Access-Control-Request-Headers.
  126. @H_502_212@#
  127. @H_502_212@#Adynamic,restrictiveconfig,wouldjustechobackthe
  128. @H_502_212@#subsetofAccess-Control-Request-Headersheaderswhichare
  129. @H_502_212@#allowedforthisresource.
  130. @H_502_212@#
  131. @H_502_212@#Thisstatic,fairlyopenconfigjustreturnsahardcodedsetof
  132. @H_502_212@#headersthatcoversmanycases,includingsomeheadersthat
  133. @H_502_212@#areofficiallyunnecessarybutactuallyneededtosupport
  134. @H_502_212@#non-conformingbrowsers
  135. @H_502_212@#
  136. @H_502_212@#Commentonsomeparticularheadersbelow:
  137. @H_502_212@#
  138. @H_502_212@#Authorization--practicallyandofficiallyneededtosupport
  139. @H_502_212@#requestsusingHTTPBasicAccessauthentication.BrowserJS
  140. @H_502_212@#canuseHTTPBAauthenticationwithanXmlHttpRequestobject
  141. @H_502_212@#reqbycalling
  142. @H_502_212@#
  143. @H_502_212@#req.withCredentials=true,and
  144. @H_502_212@#req.setRequestHeader('Authorization','Basic'+window.btoa(theusername+':'+thepassword))
  145. @H_502_212@#
  146. @H_502_212@#Counterintuitively,theusernameandpasswordfieldson
  147. @H_502_212@#XmlHttpRequest#opencannotbeusedtosettheauthorization
  148. @H_502_212@#fieldautomaticallyforCORSrequests.
  149. @H_502_212@#
  150. @H_502_212@#Content-Type--thisisa"simpleheader"onlywhenit's
  151. @H_502_212@#valueiseitherapplication/x-www-form-urlencoded,
  152. @H_502_212@#multipart/form-data,ortext/plain;andinthatcaseitdoes
  153. @H_502_212@#notofficiallyneedtobeincluded.But,ifyourbrowser
  154. @H_502_212@#codesetsthecontenttypeasapplication/json,forexample,
  155. @H_502_212@#thenthatmakestheheadernon-simple,andthenyourserver
  156. @H_502_212@#mustdeclarethatitallowstheContent-Typeheader.
  157. @H_502_212@#
  158. @H_502_212@#Accept,Accept-Language,Content-Language--thesearethe
  159. @H_502_212@#"simpleheaders"andtheyareofficiallynever
  160. @H_502_212@#required.Practically,possiblyrequired.
  161. @H_502_212@#
  162. @H_502_212@#Origin--logically,shouldnotneedtobeexplicitly
  163. @H_502_212@#required,sinceit'simplicitlyrequiredbyallof
  164. @H_502_212@#CORS.officially,itisunclearifitisrequiredor
  165. @H_502_212@#forbidden!practically,probablyrequiredbyexisting
  166. @H_502_212@#browsers(GeckodoesnotrequestitbutWebKitdoes,so
  167. @H_502_212@#WebKitmightchokeifit'snotreturnedback).
  168. @H_502_212@#
  169. @H_502_212@#User-Agent,DNT--officially,shouldnotberequired,as
  170. @H_502_212@#theycannotbesetas"authorrequestheaders".practically,
  171. @H_502_212@#mayberequired.
  172. @H_502_212@#
  173. @H_502_212@#MyComment:
  174. @H_502_212@#
  175. @H_502_212@#Thespecsarecontradictory,orelsejustconfusingtome,
  176. @H_502_212@#inhowtheydescribecertainheadersasrequiredbyCORSbut
  177. @H_502_212@#forbiddenbyXmlHttpRequest.TheCORSSpecsaysthebrowser
  178. @H_502_212@#issupposedtosetAccess-Control-Request-Headerstoinclude
  179. @H_502_212@#only"authorrequestheaders"(section7.1.5).Andthenthe
  180. @H_502_212@#serverissupposedtouseAccess-Control-Allow-Headersto
  181. @H_502_212@#echobackthesubsetofthosewhichisallowed,tellingthe
  182. @H_502_212@#browserthatitshouldnotcontinueandperformtheactual
  183. @H_502_212@#requestifitincludesadditionalheaders(section7.1.5,
  184. @H_502_212@#step8).Sothisimpliesthebrowserclientcodemusttake
  185. @H_502_212@#caretoincludeallnecessaryheadersasauthorrequest
  186. @H_502_212@#headers.
  187. @H_502_212@#
  188. @H_502_212@#However,thespecforXmlHttpRequest#setRequestHeader
  189. @H_502_212@#(section4.6.2)providesalonglistofheaderswhichthe
  190. @H_502_212@#thebrowserclientcodeisforbiddentoset,includingfor
  191. @H_502_212@#instanceOrigin,DNT(donottrack),User-Agent,etc..This
  192. @H_502_212@#isunderstandable:theseareallheadersthatwewantthe
  193. @H_502_212@#browseritselftocontrol,sothatmalicIoUsbrowserclient
  194. @H_502_212@#codecannotspoofthemandforinstancepretendtobefroma
  195. @H_502_212@#differentorigin,etc..
  196. @H_502_212@#
  197. @H_502_212@#ButifXmlHttpRequestforbidsthebrowserclientcodefrom
  198. @H_502_212@#settingthese(aspertheXmlHttpRequestspec),thenthey
  199. @H_502_212@#arenotauthorrequestheaders.Andiftheyarenotauthor
  200. @H_502_212@#requestheaders,thenthebrowsershouldnotincludethemin
  201. @H_502_212@#thepreflightrequest'sAccess-Control-Request-Headers.And
  202. @H_502_212@#iftheyarenotincludedinAccess-Control-Request-Headers,
  203. @H_502_212@#thentheyshouldnotbeechoedby
  204. @H_502_212@#Access-Control-Allow-Headers.Andiftheyarenotechoedby
  205. @H_502_212@#Access-Control-Allow-Headers,thenthebrowsershouldnot
  206. @H_502_212@#continueandexecuteactualrequest.Sothisseemstoimply
  207. @H_502_212@#thattheCORSandXmlHttpRequestspecsforbidcertain
  208. @H_502_212@#widely-usedfieldsinCORSrequests,includingtheOrigin
  209. @H_502_212@#field,whichtheyalsorequireforCORSrequests.
  210. @H_502_212@#
  211. @H_502_212@#Thebottomline:itseemsthereareheadersneededforthe
  212. @H_502_212@#webandCORStowork,whichatthemomentyoushould
  213. @H_502_212@#hard-codeintoAccess-Control-Allow-Headers,although
  214. @H_502_212@#officialspecsimplythisshouldnotbenecessary.
  215. @H_502_212@#
  216. @H_502_212@add_header'Access-Control-Allow-Headers''Authorization,Content-Type,Accept,Origin,DNT,Cache-Control,X-Mx-ReqToken,Keep-Alive,X-Requested-With,If-Modified-Since';
  217. @H_502_212@
  218. @H_502_212@#buildentireresponsetothepreflightrequest
  219. @H_502_212@#nobodyinthisresponse
  220. @H_502_212@add_header'Content-Length'0;
  221. @H_502_212@#(shouldnotbenecessary,butincludedfornon-conformingbrowsers)
  222. @H_502_212@add_header'Content-Type''text/plaincharset=UTF-8';
  223. @H_502_212@#indicatesuccessfulreturnwithnocontent
  224. @H_502_212@return204;
  225. @H_502_212@}
  226. @H_502_212@#--PUTYOURREGULARNginxCODEHERE--
  227. @H_502_212@}
  228. @H_502_212@

服务器解析流程如下:

a.首先查看http头部有无origin字段;

b.如果没有,或者不允许,直接当成普通请求处理,结束;

c.如果有并且是允许的,那么再看是否是preflight(method=OPTIONS);

d.如果是preflight,就返回Allow-Headers、Allow-Methods等,内容为空;

e.如果不是preflight,就返回Allow-Origin、Allow-Credentials等,并返回正常内容

若服务器为Nginx,可以 Nginx conf 文件中加入以下内容

[plain] view plain @H_502_212@ copy @H_502_212@
  1. @H_502_212@@H_502_212@location/{
  2. @H_502_212@add_headerAccess-Control-Allow-Origin*;
  3. @H_502_212@}

若服务器为Apache,则可以按照如下配置:

[plain] view plain @H_502_212@ copy @H_502_212@
  1. @H_502_212@@H_502_212@<IfModulemod_setenvif.c>
  2. @H_502_212@<IfModulemod_headers.c>
  3. @H_502_212@<FilesMatch"\.(cur|gif|ico|jpe?g|png|svgz?|webp)$">
  4. @H_502_212@SetEnvIfOrigin":"IS_CORS
  5. @H_502_212@HeadersetAccess-Control-Allow-Origin"*"env=IS_CORS
  6. @H_502_212@</FilesMatch>
  7. @H_502_212@</IfModule>
  8. @H_502_212@</IfModule>

为安全起见,Access-Control-Allow-Origin也可设为特定域名的方式。

在HTML5中,有些HTML元素为CORS提供了支持,如img、video新增了crossOrigin属性属性值可以为anonymoususe-credentials。比如,canvas绘图要用到跨域图片,在JavaScript中要设置img.crossOrigin="Anonymous";

[javascript] view plain @H_502_212@ copy @H_502_212@
  1. @H_502_212@var@H_502_212@img=new@H_502_212@Image,
  2. @H_502_212@canvas=document.createElement("canvas"@H_502_212@),
  3. @H_502_212@ctx=canvas.getContext("2d"@H_502_212@),
  4. @H_502_212@src="http://example.com/image"@H_502_212@;//insertimageurlhere
  5. @H_502_212@
  6. @H_502_212@img.crossOrigin="Anonymous"@H_502_212@;
  7. @H_502_212@
  8. @H_502_212@img.onload=function@H_502_212@(){
  9. @H_502_212@canvas.width=img.width;
  10. @H_502_212@canvas.height=img.height;
  11. @H_502_212@ctx.drawImage(img,0);
  12. @H_502_212@localStorage.setItem("savedImageData"@H_502_212@,canvas.toDataURL("image/png"@H_502_212@));
  13. @H_502_212@}
  14. @H_502_212@img.src=src;
  15. @H_502_212@//makesuretheloadeventfiresforcachedimagestoo@H_502_212@
  16. @H_502_212@if@H_502_212@(img.complete||img.complete===undefined){
  17. @H_502_212@img.src="data:image/gif;base64,R0lGODlhAQABAIAAAAAAAP///ywAAAAAAQABAAACAUwAOw=="@H_502_212@;
  18. @H_502_212@img.src=src;
  19. @H_502_212@}

上述配置完成后,重启服务器,CORS启用。

然后我们再刷新页面查询请求头的参数,可以发现多出一个:Access-Control-Allow-Origin:*

,到此证明服务器配置已经生效。同时我们的canvas绘图也可以正常使用了。

刷新页面返回请求响应结果后,HTTP Request Headers的内容

Remote Address:222.132.18.xx:80

Request URL:http://js.xx.com/static/activity/sq/guagua315/images/card_inner.jpg

Request Method:GET

Status Code:200 OK

Request Headersview source

Accept:image/webp,*/*;q=0.8

Accept-Encoding:gzip,deflate,sdch

Accept-Language:zh-CN,zh;q=0.8

Cache-Control:no-cache

Connection:keep-alive

Host:js.xx.com

Origin:http://act.xx.com

Pragma:no-cache

RA-Sid:7CCAD53E-20140704-054839-03c57a-85faf2

RA-Ver:2.8.8

Referer:http://act.xx.com/sq/guagua315?uuid=46124642&fid=2&sign=xxx

User-Agent:Mozilla/5.0 (Windows NT 6.1;WOW64) AppleWebKit/537.36 (KHTML,like Gecko) Chrome/40.0.2214.115Safari/537.36

Response Headersview source

Accept-Ranges:bytes

Access-Control-Allow-Origin:*

Connection:close

Content-Length:4010

Content-Type:image/jpeg

Date:Thu,12 Mar 2015 02:29:43 GMT

ETag:"54f7d1b4-faa"

Last-Modified:Thu,05 Mar 2015 03:47:00 GMT

Powered-By-ChinaCache:MISS fromCNC-WF-3-3X6

Powered-By-ChinaCache:MISS fromCNC-WF-3-3X5

Server:Tengine

Switch:FSCS

附图:


参考文章

CORS enabled image https://developer.mozilla.org/en-US/docs/Web/HTML/CORS_enabled_image

CORS on Nginx http://enable-cors.org/server_nginx.html

Nginx CORS实现JS跨域 http://www.jb51.cc/article/p-xhzdhafc-bbp.html

转载请注明出处,文章来自于freshlover的CSDN空间《Ajax跨域、Json跨域、Socket跨域和Canvas跨域等同源策略限制的解决方法

http://www.jb51.cc/article/p-dsqvmmtq-yn.html

猜你在找的Ajax相关文章