2016-12-15 102 views
0

我是新来的编码...只是想知道我在这个

<script type="text/javascript"> 

    // This example loads the "Canadian Parliament 2012" 
    // dataset from a CSV instead of from JSON.  // System.import('app').catch(function (err) { console.error(err); }); 
    $(function() { 
     Dimensions = "sector_type"; 
     Measures = ""; 
     tblname = "sample"; 
     $.ajax({ 
      method: "GET", 
      url: "http://localhost:5000/api/values/5" 
      headers: { 
       'Content-Type': 'application/json' 
      }, 
      traditional: true, 
      async: false, 

     }).success(function results(data) { 
      chartdata = data.data; 
      alert("SUCCESS"); 
     }); 





    }); 

</script> 

这是给我的未捕获的参考做错了:$不是defined.Also这是写一个小脚本从本地主机检索数据的正确方法:5000和我应该怎么做来显示数据 任何帮助深表感谢

+7

是否包含jQuery脚本? – guradio

+0

检查jquery插件是否引用到您的页面 – Bharat

+0

您的var $未定义。您需要包含用于定义$ var的查询脚本。 –

回答

1

这对我很有用。 你应该把参考jQuery链接。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 

然后替换代码

<script type="text/javascript"> 
$(document).ready(function(){ 
Dimensions = "sector_type"; 
Measures = ""; 
tblname = "sample"; 
data = $(this).serialize(); 

$.ajax({ 
method: "GET", 
url: "http://localhost:5000/api/values/5", 
headers: { 
'Content-Type': 'application/json' 
}, 
traditional: true, 
async: false, 
success:function(data){ 
chartdata = data.data; 
alert("SUCCESS"); 
} 
}); 
}); 

</script> 
+0

主线程上的同步XMLHttpRequest已被弃用,因为它对最终用户的体验有不利影响。如需更多帮助,请查看https://xhr.spec.whatwg.org/...am我错过了什么? – Venky

+0

嗨@venky async:true, – Senthil

+0

非常感谢,它似乎工作,但由于某种原因它说连接被拒绝,即时通讯运行在Linux上 – Venky

0

试试我的代码..我想它会正常工作

(function() { 
    Dimensions = "sector_type"; 
    Measures = ""; 
    tblname = "sample"; 
    $.ajax({ 
     method: "GET", 
     url: "http://localhost:5000/api/values/5", 
     headers: { 
      'Content-Type': 'application/json' 
     }, 
     traditional: true, 
     async: false 
    }).success(function results(data) { 
     chartdata = data.data; 
     alert("SUCCESS"); 
    }); 
})(); 
+0

如果JQuery库没有在页面中引用,错误将与这段代码相同:/ - 移动块似乎并不是这里的问题 – ochi

+0

他没有提到他是哪个文件插入或没有,你是正确的家伙! J查询文件必须加 –

+1

非常感谢,让我检查一下 – Venky

0

使用$(document).ready(function(){});

<script type="text/javascript"> 

// This example loads the "Canadian Parliament 2012" 
// dataset from a CSV instead of from JSON.  // System.import('app').catch(function (err) { console.error(err); }); 
$(document).ready(function() { 
    Dimensions = "sector_type"; 
    Measures = ""; 
    tblname = "sample"; 
    $.ajax({ 
     method: "GET", 
     url: "http://localhost:5000/api/values/5" 
     headers: { 
      'Content-Type': 'application/json' 
     }, 
     traditional: true, 
     async: false, 

    }).success(function results(data) { 
     chartdata = data.data; 
     alert("SUCCESS"); 
    }); 
}); 

</script> 
+0

如果在页面中没有引用JQuery库,错误将与这段代码相同:/ – ochi

+0

非常感谢,让我检查 – Venky

0

检查您是否已经包含在HTML代码jQuery库。

<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script> 
+0

这是并非真正的答案,更多评论 – ochi

0

$未定义表示您尚未在页面中添加jQuery插件。

从jquery.com下载jQuery插件并添加到您的项目中。在您的页面标题中引用该文件。

要显示数据,它取决于您要检索的数据。根据退货数据添加控制和绑定。

$(function() { 

    Dimensions = "sector_type"; 
    Measures = ""; 
    tblname = "sample"; 

    $.ajax({ 
     method: "GET", 
     url: "http://localhost:5000/api/values/5" 
     headers: { 
      'Content-Type': 'application/json' 
     }, 
     traditional: true, 
     async: false, 
     success:function (data) { 
     chartdata = data.data; 
     alert("SUCCESS"); 
     } 
    }); 
}); 
相关问题