html5使得CORS更简单
来源:互联网 发布:数据库的英文单词 编辑:程序博客网 时间:2024/06/08 19:09
以前使用CORS时比较麻烦,浏览器各种设置
<!DOCTYPE html><html><head><title></title><script type="text/javascript" src="./file.js"></script></head><body><script type="text/javascript">// Create the XHR object.function createCORSRequest(method, url) { var xhr = new XMLHttpRequest(); if ("withCredentials" in xhr) { // XHR for Chrome/Firefox/Opera/Safari. xhr.open(method, url, true); }else if (typeof XDomainRequest != "undefined") { // XDomainRequest for IE. xhr = new XDomainRequest(); xhr.open(method, url); }else { // CORS not supported. xhr = null; } return xhr;}// Helper method to parse the title tag from the response.function getTitle(text) { return text.match('<title>(.*)?</title>')[1];}// Make the actual CORS request.function makeCorsRequest() { // All HTML5 Rocks properties support CORS. var url = 'XXX'; var xhr = createCORSRequest('GET', url); if (!xhr) { alert('CORS not supported'); return; } // Response handlers. xhr.onload = function() { var text = xhr.responseText; var title = getTitle(text); alert('Response from CORS request to ' + url + ': ' + title); }; xhr.onerror = function() { alert('Woops, there was an error making the request.'); }; xhr.send();}</script><button onclick="javascript:makeCorsRequest()">Button</button></body></html>
0 0
- html5使得CORS更简单
- Console使得JS代码变得更简单
- HTML5 CORS 跨域ajax .NET 实例
- moveToThread的最简单用法(依葫芦画瓢即可)(使得线程也更偏向于信号槽的使用方法)
- moveToThread的最简单用法(依葫芦画瓢即可)(使得线程也更偏向于信号槽的使用方法)
- 人工智能使得安防领域更智能
- CORS
- CORS
- CORS
- CORS
- CORS
- CORS
- Html5更新版笔记
- 使得股市大幅很简单
- cors和jsonp的简单实现
- JS Cors Tomcat配置(简单,可用)
- ASP.NET Core CORS 简单使用
- HTML5安全:CORS(跨域资源共享)简介
- 《程序员面试金典》--平衡二叉树的检测
- leetcode58题---java解法
- example 收集(未完待续)
- C++中typename实例
- JAVA容器类解析
- html5使得CORS更简单
- ubuntu12.04 安装配置jdk1.7
- Jsp+Servlet实现文件上传下载——前台页面开发
- Unity Shader 表面着色器(Surface Shader)
- LeetCode Ugly Number II
- Android中使用VideoView播放视屏
- 八皇后问题
- 文件分隔符、几种创建File对象的方式
- POJ 3159 Candies