我有以下的jQuery代碼:jqplot沒有顯示AJAX數據
$(document).ready(function() {
var group = 'test';
$.ajax({
type: "POST",
async: false,
url: "/validate.asmx/GetGraphData",
contentType: "application/json;",
data: "{'groupBy': '" + group + "'}",
dataType: 'json',
success: function (data) {
Plot(data.d);
}
});
});
function Plot(dataIn) {
alert(dataIn);
$.jqplot('chartcontainer', [[[ 'test1', 1 ], [ 'test2', 5]]],
{
seriesDefaults: {
renderer: $.jqplot.PieRenderer,
rendererOptions: {
showDataLabels: true
}
},
legend: { show: true, location: 'e' }
}
);
}
將WebMethod(切割它進行測試後)看起來是這樣的:
[WebMethod]
public string GetGraphData(string groupBy)
{
PaymentModelDataContext db = new PaymentModelDataContext();
var q = from Event in db.TrackingEvents
group Event by Event.campaignID;
//string returnJSON;
//string returnJSON = "[";
//foreach (var grp in q)
//{
// returnJSON += "['" + grp.Key + "'," + grp.Count() + "],";
//}
//returnJSON += "]";
//var ser = new JavaScriptSerializer();
//returnJSON = ser.Serialize(q);
//return returnJSON;
return "[['test1' , 1],['test2' , 5]]";
}
如果我採取相同的字符串我返回這裏,並把它作爲文本在jQuery代碼中,情節顯示。我在劇情功能中加入了一個警報,數據就像我發送的那樣。 任何想法?
謝謝!