开发者

Unable to handle the PROTOTYPE AJAX Response

开发者 https://www.devze.com 2023-02-26 15:56 出处:网络
I am getting this format of data from my server {jobs:[{Dater:\"2010-01-01\",INCPU:\"1\"},{Dater:\"2010-01-02\",INCPU:\"2\"}]

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();

0

精彩评论

暂无评论...
验证码 换一张
取 消