简体   繁体   中英

Ajax is not working with remote server in VPN

I am trying to access a json file from a remote server using Ajax and plot and then trying to plot the graph using jqplot.

I doubt that my Ajax is not working with the remote server. the same url I can access from my browser but Ajax is not working with the same. Below is my code....Can anyone please highlight the mistake I am making:

<!DOCTYPE html>
<html>
<head>
<title>Test</title>

<link rel="stylesheet" type="text/css" href="jquery.jqplot.css" />

<script src="jqplot.canvasTextRenderer.min.js" type="text/javascript"></script>
<script src="jqplot.canvasAxisLabelRenderer.min.js" type="text/javascript"></script>
<script src="jquery-1.11.3.min.js" type="text/javascript"></script>
<script src="jquery.jqplot.js" type="text/javascript"></script>
<script src="jqplot.dateAxisRenderer.js" type="text/javascript"></script>
<script src="jqplot.categoryAxisRenderer.js" type="text/javascript" ></script>
<script src="jqplot.ohlcRenderer.js" type="text/javascript"></script>
<script src="jqplot.highlighter.js" type="text/javascript"></script>
<script src="jqplot.cursor.js" type="text/javascript"></script>
<script src="jqplot.pointLabels.min.js"  type="text/javascript"></script>

<script type="text/javascript">
$(document).ready(function() {

$.ajax({
  url: "http://172.xx.xxx.xxx/mc_measurement_new1.json",
  type: "GET"
  dataType: "jsonp",
  crossDomain:true,
  contentType:'application/json; charset=utf-8',
  success: function (data) {
    populateGraph(data);
  }
});


function populateGraph(ret) {
    var line1 = [];

    for (i = 0; i < ret.length; i++) {
      // Save the data to the relevant array. Note how date at the zeroth position (i.e. x-axis) is common for both demand and supply arrays.
      line1.push([ret[i].id, ret[i].res]);
    }

    var plot2 = $.jqplot('chart1', [line1], {  
      series:[{showMarker:false}],
      axes:{
        xaxis:{
          label:'ID',
          labelRenderer: $.jqplot.CanvasAxisLabelRenderer
        },
        yaxis:{
          label:'Delay',
          labelRenderer: $.jqplot.CanvasAxisLabelRenderer
        }
      }
  });
  };
});
</script>
</head>

<body>
<div id="chart1" style="height: 400px; width: 600px;"></div>

</body>
</html> 

When you use jsonp as the datatype, you must provide a callback, you don't have to use the success option.

Check out the jQuery api docs: http://api.jquery.com/jQuery.ajax/

Look for jsonp and jsonpCallback options.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM