跨域
来源:互联网 发布:蔬菜报价软件 编辑:程序博客网 时间:2024/06/14 10:56
//通过jquery的get方法实现跨域
// $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
// var countryCode = (resp && resp.country) ? resp.country : "";
// countryCode = countryCode.toLowerCase();
// $('#divCustomers').text(countryCode);
// localStorage.setItem('countryCode', countryCode);
// });
//通过jquery的ajax方法实现跨域
// $.ajax({
// type: "get",
// dataType:'jsonp',
// url:'https://ipinfo.io',
// success:function(resp){
// var countryCode = (resp && resp.country) ? resp.country : "";
// countryCode = countryCode.toLowerCase();
// $('#divCustomers2').text(countryCode);
// localStorage.setItem('countryCode', countryCode);
// },
// });
//通过原生javascript的封装的方法实现跨域
function jsonp(setting)
{
setting.data = setting.data || {};
setting.key = setting.key||'callback';
setting.callback = setting.callback||function(){};
setting.data[setting.key] = '__onGetData__';
window.__onGetData__ = function(data) {
setting.callback (data);
}
var script = document.createElement('script');
var query = [];
for(var key in setting.data)
{
query.push(key + '=' + encodeURIComponent(setting.data[key]));
}
script.src = setting.url + '?' + query.join('&');
document.head.appendChild(script);
document.head.removeChild(script);
}
jsonp({
url: 'http://photo.sina.cn/aj/index',
key: 'jsoncallback',
data: { page: 1, cate: 'recommend' },
callback: function(ret) {
console.log(ret)
}
});
// $.get('https://ipinfo.io', function() {}, "jsonp").always(function(resp) {
// var countryCode = (resp && resp.country) ? resp.country : "";
// countryCode = countryCode.toLowerCase();
// $('#divCustomers').text(countryCode);
// localStorage.setItem('countryCode', countryCode);
// });
//通过jquery的ajax方法实现跨域
// $.ajax({
// type: "get",
// dataType:'jsonp',
// url:'https://ipinfo.io',
// success:function(resp){
// var countryCode = (resp && resp.country) ? resp.country : "";
// countryCode = countryCode.toLowerCase();
// $('#divCustomers2').text(countryCode);
// localStorage.setItem('countryCode', countryCode);
// },
// });
//通过原生javascript的封装的方法实现跨域
function jsonp(setting)
{
setting.data = setting.data || {};
setting.key = setting.key||'callback';
setting.callback = setting.callback||function(){};
setting.data[setting.key] = '__onGetData__';
window.__onGetData__ = function(data) {
setting.callback (data);
}
var script = document.createElement('script');
var query = [];
for(var key in setting.data)
{
query.push(key + '=' + encodeURIComponent(setting.data[key]));
}
script.src = setting.url + '?' + query.join('&');
document.head.appendChild(script);
document.head.removeChild(script);
}
jsonp({
url: 'http://photo.sina.cn/aj/index',
key: 'jsoncallback',
data: { page: 1, cate: 'recommend' },
callback: function(ret) {
console.log(ret)
}
});
阅读全文
0 0
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- 跨域
- //跨域
- 跨域
- 跨域
- iOS PDF涂鸦demo
- 如何使用redis缓存来实现用户最近浏览的商品列表
- 查找素数编程
- 图片间隙问题
- IoC在Web API中的应用
- 跨域
- org.aspectj.lang.JoinPoint-中文简要API
- angular+一个输入框,往框里输入内容,在下方打印出来
- echarts 地图默认选中效果
- Quartz任务调度入门
- ReactNative Listview 中加载图片 OOM
- web.xml 的标签 和 WEB_INF 目录的作用
- 单源最短路径
- 猫哆哩的前端学习路线--开篇