How to access an array in a JSON object?

后端 未结 8 1005
感动是毒
感动是毒 2020-12-15 05:35

I have the following JSON object:

[
    {
        "comments": [
            {
                "created_at": "2011-02-09T14:42:42-08:0         


        
8条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-15 06:22

    You have to mention the dataType in the ajax request as 'JSON'. Make user you did that like below.

     $.ajax({
                url: $('#frmAddCourse').attr('action'),
                type: 'POST',
                data: $('#frmAddCourse').serialize(),
                dataType: 'JSON',
                success: function (data){
                    Materialize.toast(data['state'],2000);
                },
                error:function(){
                    Materialize.toast(errorMessage,2000);
                }
            });
    

提交回复
热议问题