Ajax无法在VPN中使用远程服务器

Ajax is not working with remote server in VPN

本文关键字:服务器 VPN Ajax      更新时间:2023-09-26

我正试图使用Ajax从远程服务器访问json文件并进行绘图,然后尝试使用jqplot绘制图形。

我怀疑我的Ajax不能与远程服务器一起工作。我可以从浏览器访问相同的url,但Ajax无法使用相同的url。下面是我的代码。。。。有人能强调一下我犯的错误吗:

<!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> 

当使用jsonp作为数据类型时,必须提供回调,而不必使用success选项。

查看jQuery api文档:http://api.jquery.com/jQuery.ajax/

查找jsonpjsonpCallback选项。