使用JSONP将数据传递给https

时间:2016-02-10 13:07:18

标签: json ajax highcharts https jsonp

我尝试了很多不同的tutarials和来自http://api.jquery.com/jQuery.getJSON/Post data to JsonP的例子,看到很多员工关于如何将json数据转换为jasonP,但我仍然无法做到,有没有人可以看到我应该在我的代码中通过https传递我的数据,我在这里使用highcharts从我的域sql server获取数据,这是在我的网页主机不同的服务器中。这是我的代码:(我知道我应该使用ajax请求但是我不知道在我的情况下,如果有人知道请帮助!)tnx。

通过getJASON获取数据,通过data.php从sql server请求获取数据:

  var Options;
  $(document).ready(function() {

     Options = {
      chart: {
            renderTo: 'container2',
            type: 'area',
            borderColor: "#3366ff",
            borderWidth:5,
            zoomType : 'x'
    },
    title: {
        text: 'Total Meeting_Logs Duration of Organization1 '
    },
    subtitle: {
        text: ' '
    },
    credits:{
        enabled:false
     },

        xAxis: {
            categories: [],
            labels: {
                align: 'center',
                x: -3,
                y: 20,
             //format data based on #datepicker which is html jquery ui date     
            //picker
                formatter: function() {
                    return Highcharts.dateFormat('%l%p',   
          Date.parse(this.value +' UTC'));
                }
            }
         },
        yAxis: {
            title: {
                text: ''
            }
        },

        tooltip: {
    backgroundColor: '#FCFFC5',
    borderColor: 'black',
    borderRadius: 10,
    borderWidth: 3
   },


  // Enable for both axes
    tooltip: {
        crosshairs: [true,true]
      },
        plotOptions: {
            line: {
                dataLabels: {
                    enabled: true
                },
                enableMouseTracking: false
            }
        },

        series: [{
                type: 'area',
                name: '',
                data: []
       }]
    }
           // here i get my data from data.php within same server

    $.getJSON("data.php", function(json){
        Options.xAxis.categories = json['category'];
        Options.series[0].name = json['name'];
        Options.series[0].data = json['data'];
        chart = new Highcharts.Chart(Options);
      });

    });
                  //this function get user request for input time period and 

                //update in my domain
    $(function() {
     $( "#datepicker2" ).datepicker({
      dateFormat: "yy-mm-dd",
      showOn: "button",
      buttonImage: "calendar.gif",
      buttonImageOnly: true,
      onSelect: function(dateText, inst) { 
        $.getJSON("data.php?dateparam1="+dateText, function(json){
            Options.xAxis.categories = json['category'];
            Options.series[0].name = json['name'];
            Options.series[0].data = json['data'];
            chart = new Highcharts.Chart(Options);
        });
      }
    });
    });

data.php:       `

    if (!$con) {
           die('Could not connect: ' . mysql_error());
               }

       mysql_select_db("moh1368_Mrs_Lemoine", $con);

      if (isset($_GET["dateparam"])) {

       $sql = mysql_query("SELECT timestamp_value, traffic_count FROM  

   foot_traffic WHERE timestamp_value LIKE '".$_GET["dateparam"]."%'");
          } else {
        $sql = mysql_query("SELECT timestamp_value, traffic_count FROM 
     foot_traffic        WHERE timestamp_value LIKE '2013-02-01%'");
       }
     $result['name'] = 'Foot Traffic Count';
     while($r = mysql_fetch_array($sql)) {
     $datetime = $r['timestamp_value'];
     $result['category'][] = $datetime;
     $result['data'][] = $r['traffic_count'];
      }

      print json_encode($result, JSON_NUMERIC_CHECK);

     mysql_close($con);
     ?>`

0 个答案:

没有答案