0

here i want to print the absentList array values in loop using jquery and ajax,

Here is my AJAX code

    $.ajax({
     type:'POST',
     url :"admin_getabsentlist",
     data: $('form#subjectForm').serialize(),
     success: function(data) {
     var res=jQuery.parseJSON(data);
     console.log(res);
    if(res['status']=='Success'){

   $.each( res['data'], function( key, value ) {

      alert(value.absentList);

    });
    }else{
        alert('else part');
    }
     },
     error:function(exception){
     alert('Exeption:'+exception);
    }
})

here if i am printing the values like console.log(res); means i am getting the results like

I am getting results

object {status: "Success", data: Object}
data:Object
absentList:Array(2)
0:'Kani'
1:'yuvi'

now i want to print the absentList values so iam using forloop like this

Forloop

 if(res['status']=='Success'){

   $.each( res['data'], function( key, value ) {

      alert(value.absentList);

    });

but here i am getting the absentList values i am getting undefined ,please tell me anyone

Expected results

in alert box i want print the values of Kani and yuvi

1
  • 2
    Iterate absentList i.e $.each(res.data.absentList, function (key, value) { alert(value); }); Commented Apr 13, 2017 at 10:47

1 Answer 1

1

Just access the result object property containing data in your each loop

if(res['status']=='Success'){    
      $.each(res['data'].absentList, function( key, value ) {
          alert(value);
      });
}
Sign up to request clarification or add additional context in comments.

2 Comments

@subikshanM Welcome :)
@mr this answer not suitable for me

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.