いくつかのグラフを生成する必要があり、各グラフ データは mvc コントローラーから取得する必要があります。
だから私は以下のjqueryを使ってjqueryからmvcへのajax呼び出しをしています
$(".emailgraphs").each(function () {
YAHOO.Report.Print("Email", $(this).attr("responsefield"), $(this).attr("id"), $(this).attr("metricid"));
});
Print: function (name, graphid, divid, metricid) {
try {
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: m_oReport.ds,
data: JSON.stringify(m_oReport.printp(name, graphid, metricid)),
beforeSend: function () {
//Displays loading image before request send, till we get response.
//$("#" + divId).addClass("loading");
},
success: function (data) {
// if they define a success function (s), call it and return data to it.
if (typeof m_oReport.prints === "function") {
m_oReport.prints(data, divid, name)
}
},
error: function (err) {
$("#" + divid).html(err);
}
});
}
catch (err) { alert("catch"); }
}
問題は、呼び出しが非同期であることです。グラフが 1 つ得られることもあれば、そのようなグラフが 2 つ得られることもあれば、何も得られないこともあります。
これに対する修正はありますか?