ajax利用json进行服务器与客户端的通信

1.JQuery中$.ajax()方法参数详解

http://blog.sina.com.cn/s/blog_4f925fc30100la36.html

 

2.服务器端获取String que=request.getParameter("que");

 

3.客户端请求完整代码(highcharts)。

<!DOCTYPE html>
<html>
<head>
<title>MyHtml.html</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="keywords" content="keyword1,keyword2,keyword3">
<meta name="description" content="this is my page">
<meta name="content-type" content="text/html; charset=UTF-8">

<!--<link rel="stylesheet" type="text/css" href="./styles.css">-->

</head>

<body>
    <!--      <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script> 
      <script src="http://cdn.bootcss.com/jquery/1.11.2/jquery.min.js"></script>
      <script type="text/javascript" src="../js/highcharts.js"></script>-->
    <script src="http://cdn.hcharts.cn/jquery/jquery-1.8.3.min.js"></script>
    <script src="http://cdn.hcharts.cn/highcharts/highcharts.js"></script>
    <script type="text/javascript">
        $(function() {
            //$("input[type=button]").bind("click", showChart);
            //alert('error!');
            $('#show-button').on('click', function(e) {
                showChart();
            });

            $('#clear-button').on('click', function(e) {
                clearPlot();
            });
        });

        var chart;

        function clearPlot() {
            //console.log("clear plot data!!!");
            var series = chart.series;
            while (series.length > 0) {
                series[0].remove(false);
            }
            chart.redraw();
        };
        function showChart() {
            $.ajax({
                url : "servlet/Charts",
                type : "POST",
                dataType : "json",
                data : {
                    "que" : $("#inputque").val()
                },
            
                success : function(data) {
                    var json = eval(data);
                    if (json != "" && json != null) {
                            chart = new Highcharts.Chart({
                            chart : {
                                renderTo : 'container',
                                type : 'line'
                            },
                            title : {
                                text : '话题趋势分析'
                            },
                            subtitle : {
                                text : ''
                            },
                            xAxis : {
                                categories : json.categories
                            },
                            yAxis : {
                                title : {
                                    text : '百分比 (%)'
                                },
                                min : 0
                            },
                            plotOptions : {
                                line : {
                                    dataLabels : {
                                        enabled : true
                                    },
                                    enableMouseTracking : true
                                }
                            },
                            tooltip : {
                                formatter : function() {
                                    return '<b>' + this.series.name
                                            + '</b><br/>' + this.x + ': '
                                            + this.y + ' 次';
                                }
                            },
                            series : json.series
                        });
                        
                        
                        chart.settitle(null,null,true);
                    }
                    

                },
                error : function() {
                    alert('error!');
                }

            });

        }
    </script>






    <div style="margin:auto;text-align:center;">
        <div style="padding:10px;">
            <input type="text" name="que" id="inputque"> <input
                type="button" id="show-button" value=" Test Highcharts " /> <input
                type="button" id="clear-button" value="clean" />
        </div>





        <div id="container"
            style="height:480px;width:980px;background-color:#efefef;"></div>
    </div>
</body>
</html>
View Code

 

转载于:https://www.cnblogs.com/XDJjy/p/4476107.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值