0

Below is my Json Data received from Ajax response.

{
    "error": {
        "errorCode": "0001",
        "errorText": "SUCCESS"
    },
    "responselist": [
        {
            "count": 2,
            "event": [
                {
                    "startDate": null,
                    "eventId": 1234,
                    "eventName": "Interview",
                    "modifiedUser": "User",
                    "eventTypeCode": "1",
                    "eventVenue": null,
                    "eventSpecialInst": "isnsdf",
                    "eventStatusCode": "OP",
                    "eventLangCode": "Eng",
                    "eventDesc": "sdfsadfsd",
                    "fromEmailId": "[email protected]",
                    "rsvpDeadline": 5,
                    "canceledInd": "yes",
                    "canceldEmailText": "sdfasdfasdfasfasdfasdfasdf",
                    "daysToWaitlistLastCall": 5,
                    "daysToReminderAdmin": 6,
                    "daysToReminderEvent": 3,
                    "daysToReminderInvitation": 2,
                    "endDate": null,
                    "venueAddrLine1": null,
                    "venueAddrLine2": null,
                    "venueAddrLine3": null,
                    "cityCode": null,
                    "stateCode": null,
                    "appId": null,
                    "modifiedDate": "2010-12-16",
                    "countryCode": null,
                    "zipCode": null,
                    "user_id": null,
                    "updateFlag": "R"
                },
                {
                    "startDate": null,
                    "eventId": 4321,
                    "eventName": "Seasonal Hiring",
                    "modifiedUser": "User",
                    "eventTypeCode": "1",
                    "eventVenue": null,
                    "eventSpecialInst": "isnsdf",
                    "eventStatusCode": "OP",
                    "eventLangCode": "Eng",
                    "eventDesc": "sdfsadfsd",
                    "fromEmailId": "[email protected]",
                    "rsvpDeadline": 5,
                    "canceledInd": "yes",
                    "canceldEmailText": "sdfasdfasdfasfasdfasdfasdf",
                    "daysToWaitlistLastCall": 5,
                    "daysToReminderAdmin": 6,
                    "daysToReminderEvent": 3,
                    "daysToReminderInvitation": 2,
                    "endDate": null,
                    "venueAddrLine1": "KFC",
                    "venueAddrLine2": "The Forum",
                    "venueAddrLine3": "Koramangala",
                    "cityCode": "Bangalore",
                    "stateCode": "Karnataka",
                    "appId": null,
                    "modifiedDate": "2010-12-16",
                    "countryCode": "India",
                    "zipCode": "560040",
                    "user_id": null,
                    "updateFlag": "R"
                }
            ]
        }
    ]
}

Using below code to extract information inside event object. But I am not able to do it. Need guidance.

$.ajax({ url:"<%=request.getContextPath()%>/service/showInvitedEvents/21",

         dataType:"json", 
         success: function(jsonData) 
         {
           alert("Inside response success");

           $.each(jsonData.responselist.event,function(i,item)
          $.each(Employees,function(i,item)
           {
             alert('Iteration is' + i);
            var teventName = item.eventName;

            var teventVenue = item.eventVenue;
            var tstartDate = item.startDate;
            var tendDate = item.endDate;
            var tstarend = tstartDate +" - "+ tendDate ;            

            $("#eventTable tbody").append("<tr><td><a id="+teventName+i+" href=<%=request.getContextPath()%>/service/session/1234>"+teventName+"</a></td><td>"+teventVenue+"</td><td>"+tstarend+"</td></tr>");

           }); 
2
  • 1
    You don't loop over JSON. You decode the JSON, then loop over the resultant JavaScript objects. Commented Dec 21, 2010 at 5:14
  • Unrelated to the question but rather a tip: jQuery-append is pretty resource intensive. Better concatenate it with a variable (via +) and then use one jQuery-append when the string is complete. Commented Dec 21, 2010 at 8:23

2 Answers 2

3

First of all you can't loop over jsonData.responselist.event. jsonData.responselist is an array so either need to make a double loop or if you always know there is one and only one item in responslist you could loop over jsonData.responselist[0].event

For the rest of it I'm not sure why you have this row:

$.each(Employees,function(i,item)

Looks like a misstake to as it isn't valid there(the syntax is wrong and it hides both i and item from the real each).

Sign up to request clarification or add additional context in comments.

1 Comment

Yes..$.each(Employees,function(i,item) was a typo errro my mistake. Followed your suggestion and I worked fine. Thanks a lot.
0

What is the purpose of the following line in your code:?

$.each(Employees,function(i,item)

Try removing it and see what happens.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.