I am getting this format of data from my server
{jobs:[{Dater:"2010-01-01",INCPU:"1"},{Dater:"2010-01-02",INCPU:"2"}]
new Ajax.Request('/HumblFin/Serv',
onSuccess: function(transport){
var response = transport.responseText;
drawChart(response);
function drawChart(response)
{
alert(response.jobs.length);
for (var i = 0; i < response.jobs.length; i++) {
priceData.push([i, response.jobs[i].INCPU]);
dateData.push(response.jobs[i].Dater);
}
开发者_StackOverflow社区 }
response.jobs is undefined
Please tell me how to handle resposne in this case ??
transport.responseText
is not a JSON object, it is a string.
Use var response = transport.responseJSON;
if the Content-type of the request is set to application/json
else use
var response = transport.responseText.evalJSON();
精彩评论