原生JS跨域
来源:互联网 发布:情义知多少日本电影 编辑:程序博客网 时间:2024/06/05 02:51
<!doctype html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
<button id="btn">click</button>
</body>
<script type="text/javascript">
function $(str){
return document.getElementById(str)
}
function CreateScript(src) {
var Scrip=document.createElement('script');
Scrip.src=src;
document.body.appendChild(Scrip);
}
function jsonpcallback(json) {
console.log(json);//Object { email="中国", email2="中国222"}
}
$('btn').onclick=function(){
CreateScript("http://localhost:8888/a/gct?id=001&callback=jsonpcallback")
}
/*
*兼容ie的跨域:
*/
// function cb(r){
// console.info(r.data);
// }
// function ls(url,cb){
// var h = document.head||document.getElementsByTagName('head')[0]||document.documentElement,
// s = document.createElement('script');
// s.setAttribute('src',url);
// h.appendChild(s);
// document.addEventListener ? s.addEventListener('load',cb,false):
// s.onreadystatechange = function(r){
// if(this.readyState == 'loaded' || this.readyState == 'complete'){
// h.removeChild(s);
// cb && cb(r);
// }
// }
// }
// ls('http://mystock.eastmoney.com/mystock.aspx?f=gs&cb=cb&g=35540042&0.5394658758305013',cb);
/*requirejs跨域:需要将callback的回调函数改为define,而且不需要实现*/
// require(['http://mystock.eastmoney.com/mystock.aspx?f=gs&cb=define&g=35540042&0.5394658758305013'],function(r){
// console.info(r.data);
// })
</script>
</html>
<html>
<head>
<title></title>
<meta name="viewport" content="width=device-width,initial-scale=1.0">
</head>
<body>
<button id="btn">click</button>
</body>
<script type="text/javascript">
function $(str){
return document.getElementById(str)
}
function CreateScript(src) {
var Scrip=document.createElement('script');
Scrip.src=src;
document.body.appendChild(Scrip);
}
function jsonpcallback(json) {
console.log(json);//Object { email="中国", email2="中国222"}
}
$('btn').onclick=function(){
CreateScript("http://localhost:8888/a/gct?id=001&callback=jsonpcallback")
}
/*
*兼容ie的跨域:
*/
// function cb(r){
// console.info(r.data);
// }
// function ls(url,cb){
// var h = document.head||document.getElementsByTagName('head')[0]||document.documentElement,
// s = document.createElement('script');
// s.setAttribute('src',url);
// h.appendChild(s);
// document.addEventListener ? s.addEventListener('load',cb,false):
// s.onreadystatechange = function(r){
// if(this.readyState == 'loaded' || this.readyState == 'complete'){
// h.removeChild(s);
// cb && cb(r);
// }
// }
// }
// ls('http://mystock.eastmoney.com/mystock.aspx?f=gs&cb=cb&g=35540042&0.5394658758305013',cb);
/*requirejs跨域:需要将callback的回调函数改为define,而且不需要实现*/
// require(['http://mystock.eastmoney.com/mystock.aspx?f=gs&cb=define&g=35540042&0.5394658758305013'],function(r){
// console.info(r.data);
// })
</script>
</html>
0 0
- 原生JS跨域
- 原生js,ajax跨域
- 原生JS
- 原生js
- JS原生
- 原生JS
- 原生js通过jsonp跨域-模拟搜索引擎
- Ajax(原生js实现、jQuery实现、跨域)
- 原生js周选择器
- js原生函数bind
- 原生js拼图游戏
- 原生js cookie
- 原生js弹出框
- js原生拖拽
- js原生offsetParent解析
- 原生Js的bind
- JS原生拖拽
- 原生js学习网址
- aspx repeate控件多级关联
- 卡特兰数的证明及应用
- 快速排序
- Redis 的跳跃表实现
- 寒風的Cocos2dx之旅之地图编辑器的使用
- 原生JS跨域
- NHibernate3剖析:Query篇之NHibernate.Linq增强查询
- C++ primer【笔记】关联容器 map
- leetcode_House Robber II
- [Material Design]使用Toolbar + DrawerLayout快速实现高大上菜单侧滑
- 判断图片加载完
- 《数据结构与算法分析》二叉堆详解
- ISE软件的程序加载
- POJ 题目1204 Word Puzzles(AC自动机,多个方向查询)