zoukankan      html  css  js  c++  java
  • jquery的jsonp相关

    <!DOCTYPE html>
    <html>
    <head >
    <meta charset="utf-8">
    <script src="../../js/jquery-1.9.1.min.js"></script>
    <script src="../../js/highmaps/highmaps.js"></script>
    <script src="../../js/highmaps/drilldown.js"></script>
    <script src="../../js/highmaps/exporting.js"></script>
    </head>

    <body>
    <!--<div id="container" style="height:450px;"></div>-->
    <script type="text/javascript">

    Highcharts.setOptions({
    lang: {
    drillUpText: '< 返回 “{series.name}”'
    }
    });
    var map = null,
    // geochina = 'https://data.jianshukeji.com/jsonp?filename=geochina/';
    // $.getJSON(geochina + 'china.json&callback=?', function(mapdata) {//中国//https://jshare.com.cn/highmaps/FSSm7A //https://data.jianshukeji.com/
    // geochina = 'http://192.168.0.62:8082/';
    geochina = 'http://192.168.0.62:8082/jsonp/geo?filename=';
    $.getJSON(geochina + 'zhejiang.json&callback=?', function(mapdata) {//浙江
    //地图数据 https://data.jianshukeji.com/jsonp?filename=geochina/zhejiang/hangzhou.json
    //地图数据 https://data.jianshukeji.com/jsonp?filename=geochina/zhejiang.json
    var data = [];
    // 随机数据
    Highcharts.each(mapdata.features, function(md, index) {
    var tmp = {
    name: md.properties.name,
    value: Math.floor((Math.random() * 100) + 1) // 生成 1 ~ 100 随机值
    };
    if(md.properties.drilldown) {
    tmp.drilldown = md.properties.drilldown;
    }
    data.push(tmp);
    });
    map = new Highcharts.Map('container', {
    chart: {
    events: {
    drilldown: function(e) {
    this.tooltip.hide();
    console.log(e);
    // 异步下钻
    if (e.point.drilldown) {
    var pointName = e.point.properties.fullname;
    map.showLoading('下钻中,请稍后...');
    // 获取二级行政地区数据并更新图表
    console.dir(geochina);
    $.getJSON(geochina + e.point.drilldown + '.json&callback=?', function(data) {
    // $.getJSON(url, function(data) {
    data = Highcharts.geojson(data);
    Highcharts.each(data, function(d) {
    if(d.properties.drilldown) {
    d.drilldown = d.properties.drilldown;
    }
    d.value = Math.floor((Math.random() * 100) + 1); // 生成 1 ~ 100 随机值
    });
    map.hideLoading();
    map.addSeriesAsDrilldown(e.point, {
    name: e.point.name,
    data: data,
    dataLabels: {
    enabled: true,
    format: '{point.name}'
    }
    });
    map.setTitle({
    text: pointName
    });
    });
    }
    },
    drillup: function() {
    map.setTitle({
    text: '浙江省'
    });
    }
    }
    },
    title: {
    text: '浙江省'
    },
    subtitle: {
    useHTML: true,
    // text: '点击查看 <a href="https://www.hcharts.cn/mapdata" target="_blank">地图数据及详情</a>,注意县级数据为收费数据,如果您有需要,请 <a href="https://highcharts.com.cn/data" target="_blank">联系我们购买</a>'
    },
    mapNavigation: {
    enabled: true,
    buttonOptions: {
    verticalAlign: 'bottom'
    }
    },
    tooltip: {
    useHTML: true,
    headerFormat: '<table><tr><td>{point.name}</td></tr>',
    pointFormat: '<tr><td>全称</td><td>{point.properties.fullname}</td></tr>' +
    '<tr><td>行政编号</td><td>{point.properties.areacode}</td></tr>' +
    '<tr><td>父级</td><td>{point.properties.parent}</td></tr>' +
    '<tr><td>经纬度</td><td>{point.properties.longitude},{point.properties.latitude}</td></tr>' ,
    footerFormat: '</table>'
    },
    // colorAxis: {
    // min: 0,
    // minColor: '#fff',
    // maxColor: '#006cee',
    // labels:{
    // style:{
    // "color":"red","fontWeight":"bold"
    // }
    // }
    // },
    series: [{
    data: data,
    mapData: mapdata,
    joinBy: 'name',
    name: '浙江省',
    states: {
    hover: {
    color: '#a4edba'
    }
    }
    }]
    });
    });
    </script>
    <div id="container" style="height:850px;"></div>

    </body>
    </html>


    、、、、、、、、、、、、、、、、、、、、、

    后端:
    package com.hzunitech.platform.mvc.jsonp;

    import com.hzunitech.platform.annotation.Controller;
    import com.hzunitech.platform.mvc.base.BaseController;
    import com.jfinal.log.Log;

    @Controller("/jsonp")
    public class JsonpController extends BaseController {

    @SuppressWarnings("unused")
    private static final Log log = Log.getLog(JsonpController.class);

    public void index() {
    // 客户端请求参数,js函数名称
    String jsonpCallback = getPara("callback");

    // json数据
    String json = "{'content':'我是远程b.com/remote.js带来的数据'}";

    // 返回jsonp格式数据
    //jquery定义了名为jsonpCallback的js函数,在渲染返回的javascript text时执行了该函数,并将数据结果作为参数传入该js函数
    renderJavascript(jsonpCallback + "(" + json + ");");
    }

    public void geo() {
    // 客户端请求参数,js函数名称
    String jsonpCallback = getPara("callback");
    log.info(jsonpCallback);
    System.out.println(jsonpCallback);

    // json数据
    String json = "{'content':'我是远程b.com/remote.js带来的数据'}";

    // 返回jsonp格式数据
    renderJavascript(jsonpCallback + "(" + json + ");");
    }

    }


  • 相关阅读:
    愿你始终不移真心
    beautiful sentences
    (转)Design Pattern 新解(非常经典贴近生活)
    简述.Net下的应用程序授权。(转)
    thin的调试汇集
    Asp.net1.0 升级 ASP.NET 2.0 的几个问题总结 (转)
    Microsoft .NET Pet Shop 4 架构与技术分析 (转)
    面向对象编程,我的思想[上](转)
    七个问题:经济学常识 (转),真的很好,值的思考
    .NET控件收集(转)
  • 原文地址:https://www.cnblogs.com/YuyuanNo1/p/9183096.html
Copyright © 2011-2022 走看看