CORS、Ajax和Cookie
发布时间:2020-12-16 01:29:32 所属栏目:百科 来源:网络整理
导读:CORS是ajax跨域请求的一个解决方案,详细见: 浏览器同源政策及其规避方法 跨域资源共享 CORS 详解 ajax可以设置请求头,和get响应头 。 jQuery and AJAX response header How can I add a custom HTTP header to ajax request with js or jQuery? 先感受一
CORS是ajax跨域请求的一个解决方案,详细见: 浏览器同源政策及其规避方法 ajax可以设置请求头,和get响应头。 jQuery and AJAX response header 先感受一下,编写index.html: <!DOCTYPE html> <html> <head> <title>test</title> </head> <body> <button id="test">click</button> <script src="//cdn.bootcss.com/jquery/3.1.0/jquery.min.js"></script> <script> $('#test').on('click',function(){ console.log('click me'); var url = 'https://api.github.com/users/octocat/gists'; var geturl = $.ajax({ type: "GET",url: 'https://api.github.com/users/octocat/gists',success: function (data) { console.log('header:n',geturl.getAllResponseHeaders()); console.log('data:n',data); } }); }); </script> </body> </html> npm安装http-server模块,在index.html目录下执行http-server命令,浏览器打开 这个响应头是被过滤过的,另外原则上是无法获取Set-cookie的值。 见How to get a cookie from an AJAX response? 。 其他jQuery如何获取响应头: http://api.jquery.com/jQuery.ajax/#jqXHR (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |