0

I have following output in json from codeigniter controller. I want to get data of res3 and res4 but I can't get it. Any one can help me How can I do this.

<script>
function createDiv(data) {
  var dynamicHTML = '';
  var innerContent = '';
  alert(data.res4.Status);
  for (var i = 0; i < data.res2.length; i++) {


            if(data.res2[i].paid_type == 1) {

                    if(data.res4.A_Submit_Status == "success") {
                      innerContent += '<div class="input-group" style="border-color:#3D8EB9; box-shadow: 1px 1px 1px 1px #888888; margin-bottom: 3px; background-color: #fff;">'+
                      '<label style="padding:10px 10px;">' + data.res2[i].Paper_Name + '</label>' +
                      '<span class="input-group-btn" style="padding-top:10px;">' +
                        '<button class="btn btn-info" type="button">Analysis 1</button>' +
                      '</span>'+
                      '</div>';
                    } else {
                        innerContent += '<div class="input-group" style="border-color:#3D8EB9; box-shadow: 1px 1px 1px 1px #888888; margin-bottom: 3px; background-color: #fff;">'+
                        '<label style="padding:10px 10px;">' + data.res2[i].Paper_Name + '</label>' +        
                        '<span class="input-group-btn" style="padding-top:10px;">' +
                            '<button class="btn btn-info" type="button">Take Test 1</button>' +
                        '</span>'+
                        '</div>';
                    }

            } else {
                    if(data.res4.A_Submit_Status == "success"){
                        innerContent += '<div class="input-group" style="border-color:#3D8EB9; box-shadow: 1px 1px 1px 1px #888888; margin-bottom: 3px; background-color: #fff;">'+
                        '<label style="padding:10px 10px;">' + data.res2[i].Paper_Name + '</label>' +                                
                        '<span class="input-group-btn" style="padding-top:10px;">' +
                            '<button class="btn btn-info" type="button">Analysis 2</button>' +
                        '</span>'+
                        '</div>'; 
                    } else {
                        innerContent +=  '<div class="input-group" style="border-color:#3D8EB9; box-shadow: 1px 1px 1px 1px #888888; margin-bottom: 3px; background-color: #fff;">'+
                        '<label style="padding:10px 10px;">' + data.res2[i].Paper_Name + '</label>' +
                        '<span class="input-group-btn" style="padding-top:10px;">' +
                            '<button class="btn btn-info" type="button">Take Test</button>' +
                        '</span>'+
                        '</div>';
                    }
             }
        }

  dynamicHTML += '<div id="' + data.res2.Paper_Type + '" class="tabcontent" style="border:none;">' + innerContent + '</div>';
  $('div#tabs_data').append(dynamicHTML);
}
</script>

Output is here.

{"user":"[email protected]",
    "res2":[{"id":"1","Paper_Name":"sm1","Paper_Type":"ss","paid_type":"0"},{"id":"2","Paper_Name":"    ss-2","Paper_Type":"ss","paid_type":"1"},{"id":"3","Paper_Name":"ss-3","Paper_Type":"ss","paid_type":"1"},{"id":"4","Paper_Name":"ss-4","Paper_Type":"ss","paid_type":"1"}],
    "res3":[{"User_id":"[email protected]","Name":"mahi mahi","Phone":"2147483647","Txnid":"2147483647","Amount":"120","Product_Info":"ss","encryptedPaymentId":"CBEC29993C2DAE0B37453BFAD285CB87","Status":"success","Date_Time":"2017-04-20 12:22:49"}],
    "res4":[{"A_User_id":"[email protected]","A_Paper_Name":"ss-1","A_Paper_Type":"ss","A_Submit_Status":"success","A_Date_Time":"2017-04-21 04:33:11"}]}

I try above code but it is not working...

1 Answer 1

1

res3 & res4 are array of single object. So doing

res3[0] & rers[0] will give their data

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

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.