繁体   English   中英

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

[英]Ajax is not working with remote server in VPN

我试图使用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作为数据类型时,必须提供一个回调,而不必使用成功选项。

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

查找jsonpjsonpCallback选项。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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