2010-04-27 23 views
0

我試圖檢索一些JSON來進入一個海軍報曲線圖。我知道json是正確的,因爲我硬編碼它檢查,但我很確定我沒有通過,因爲它沒有顯示出來。 這裏的JavaScript:問題傳遞到JSON jquery的曲線圖(海軍報)

var total = $.ajax({ 
    type: "POST", 
    async: false, 
    url: "../api/?key=xxx&api=report&crud=return_months&format=json" 
}).responseText; 
//var total = $.evalJSON(total); 
var plot = $.plot($("#placeholder"),total); 

這裏的JSON:

[ { data: [[1,12], [2,43], [3,10], [4,17], ], label: "E-File"}, { data: [[1,25], [2,35], [3,3], [4,5], ], label: "Bank Products" }, { data: [[1,41], [2,87], [3,30], [4,29], ], label: "All Returns" } ], {series: {lines: { show: true },points: { show: true }}, grid: { hoverable: true, clickable: true }, yaxis: { min: 0, max: 100 }, xaxis: { ticks: [[1,"January"],[2,"February"],[3,"March"],[4,"April"],[5,"May"],[6,"June"],[7,"July"],[8,"August"],[9,"September"],[10,"October"],[11,"November"],[12,"December"]] }} 

回答

1

務必將您的dataType: "json"選項也是如此。順便說一句,你能做到這一點的success回調函數以及不鎖定用戶界面,同時等待響應,像這樣:

$.ajax({ 
    type: "POST", 
    dataType: "json", 
    url: "../api/?key=xxx&api=report&crud=return_months&format=json", 
    success: function(total) { 
    var plot = $.plot($("#placeholder"),total); 
    //do more work if needed 
    } 
}); 

或者,使用$.post()做同樣在較短的形式,就像這樣:

$.post("../api/?key=xxx&api=report&crud=return_months&format=json", 
    function(total) { 
    var plot = $.plot($("#placeholder"),total); 
    //do work 
    }, "json"); 
+0

唉太多的常見錯誤。 謝謝尼克:-) – 2010-04-27 02:06:28

+0

其實我只是嘗試過兩種解決方案,都沒有工作 – 2010-04-27 02:32:33

+0

@亞當 - 澄清一下?不成功的'成功'回調沒有運行,這是錯誤的,其他? – 2010-04-27 02:35:10