Skip to content Skip to sidebar Skip to footer

How To Process Json Output In Ajax?

I have this code snippet in .js file $(function () { // KeyDates var url = 'http://localhost:8732/Design_Time_Addresses/Intel.IIP.MDF.WCF/ProgramCalendarService/GetKeyDates

Solution 1:

You probably want to know how to access an object's props. For that, use the for in loop to iterate over the object's values:

success: function (GetKeyDatesCalendarDataNew) {
   for(var key inGetKeyDatesCalendarDataNew)
       {
           var value = GetKeyDatesCalendarDataNew[key];
           // do somehitng based on the key and/or value iterated
       }
}

Solution 2:

For this case, the argument of the success function is the evaluated JSON that was returned from the Ajax request. Therefore GetKeyDatesCalendarDataNew, which you should rename to something like data, becomes the actual data that your server returned.

You can only process the data if you know its structure. One simple way of knowing this would be to do console.log(GetKeyDatesCalendarDataNew) and then easily process it with a for loop if it's an array or for x in.. if it's an object.

Solution 3:

You can use JQuery "getJSON" function where you need to pass the url and specify a callback function.Your ajax call will be handled by the getJSON function. In the callback function, you can access the Keys as properties. A nice example

Lav G

Solution 4:

$.each(GetKeyDatesCalendarDataNew,function(key,value){
    //do something here
})

Post a Comment for "How To Process Json Output In Ajax?"