我很新的Web開發,我通常在服務器端的工作。我正在開發一個小型的電子愛好項目,我的網絡上有一個netduino服務器json請求。該netduino這種格式返回JSON:highchart json ajax問題
[ { "sensor" : "bk", "temp" : "68.9000015", "time" : "01/01/2009 01:04:46"},{ "sensor" : "mt", "temp" : "69.0124969", "time" : "01/01/2009 01:04:46"},{ "sensor" : "hlt", "temp" : "68.9000015", "time" : "01/01/2009 01:04:46"} ]
我想有傳感器是我seriess {BK,MT,HLT}(還有兩個系列在此回報)
我的Ajax請求似乎並沒有被髮送到達我netduino,在IM監控請求的HttpFox並沒有看到什麼192.168.0.11 ......
這裏是JS:
//data arrays for holding the points
var HLT=[],
MT =[],
BK =[],
PC =[],
CL =[];
var chart;
//after DOM is loaded setup timeout to call the ajax method
$(document).ready(function() {
setInterval(reqData, 5000);
options.series[0].data = HLT;
options.series[1].data = MT;
options.series[2].data = BK;
options.series[3].data = PC;
options.series[4].data = CL;
//call function to render the chart and setup the options
renderChart();
});
//this function requests the data
function reqData(){
$.ajax({
url: "http://192.168.0.11/"+Math.random(),//using math.random to avoid browser caching
contentType: "application/json; charset=utf-8",
success: mergeData(data)
});
}
//this function merges the data and refreshes the table
function mergeData(data){
//$(this).addClass("done");
}
function renderChart(){
chart = new Highcharts.Chart(options);
}
圖表呈現WHE在頁面加載但我看不到reqData被調用。請幫忙。還有什麼是更新系列數據的好方法?林不好與JavaScript會在系列名稱工作的foreach匹配?我想繪製臨時圖的臨時(y軸)和日期時間(x軸)。
謝謝!
---編輯1/23/2012 ---
我不是什麼問題是遺憾很清楚,在這個函數:
//after DOM is loaded setup timeout to call the ajax method
$(document).ready(function() {
setInterval(reqData, 5000);
options.series[0].data = HLT;
options.series[1].data = MT;
options.series[2].data = BK;
options.series[3].data = PC;
options.series[4].data = CL;
//call function to render the chart and setup the options
renderChart();
});
的reqData()函數沒有得到(通過在httpfox中看不到請求192.168.0.11來驗證),然而renderChart()被調用...任何想法?
Thay ip是我的局域網上的NAT'd IP。這個頁面將在我的局域網上,既有託管頁面的web服務器,也有我返回json的服務是本地的。我真的做了一個職位,至少我不打算,只是得到。 – cobolstinks
如果您的頁面和正在運行的服務位於同一臺主機上,我建議使用顯式路徑作爲Ajax URL - '/ path/to/the/page'。你確定你的AJAX請求的URL是'「http://192.168.0.11/」+ Math.random()'?另外,對於JSONP,如果我沒有記錯,它只適用於GET。 –
對不起,我感到困惑。 ajax客戶端和服務器不在同一個主機上。客戶端.0.104和服務器是0.11。我確定的網址。那就是我從中獲取示例數據的地方。 – cobolstinks