2016-12-15 109 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"); 
     } 
    }); 
}); 
相關問題