skip to Main Content

I have an output like this.

[{…}]
0:
id: 3
url_generation: "https://mail.google.com/mail/u/0/#sent"
status: "status one"
certificate: "[{"med_sbj_list":"Certificate1"},{"med_sbj_list":"Certificate2"},{"med_sbj_list":"Certificate3"},{"med_sbj_list":null},{"med_sbj_list":null},{"med_sbj_list":null}]"
name: "Doctor 1"
alphabet_name: "Doctor one"
image: "/doctor_photos/GSmdfr_Screenshot_20200114_102036.jpg"
image_caption: "this is an image caption"
image_alt: "image alt"
industry: "industry two"
conference: "[{"conf":"Conference1"},{"med_sbj_list":"Conference2"},{"conf":"Conference3"},{"conf":null},{"conf":null},{"conf":null}]"
birthday: "03-6-2018"
place_of_birth: "cebu city"
career_academic_back: "[{"from_year":"1991","from_month":"02","from_desc":"aaa","to_year":"1995","to_month":"06","to_desc":"bbb"}]"
career_work_exp: "[{"we_from_year":"1997","we_from_month":"05","we_from_desc":"ccc","we_to_year":"1997","we_to_month":"06","we_to_desc":"ddd"}]"
career_awards: "[{"from_year":"1998","from_month":"08","from_desc":"eee","to_year":"1999","to_month":"09","to_desc":"fff"}]"
sort_career: "1"
hospital_office: "industry one"
department: "[{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"},{"med_sbj_list":"industry one"}]"
doctor_comment: "this is a sample comment of the doctor."
created_at: "2020-01-22 03:50:28"
updated_at: "2020-01-22 03:50:28"
__proto__: Object
length: 1
__proto__: Array(0)

And I want to get the certificate and conference value that are in json type and put it in the textboxes individually. See picture below.

enter image description here

These is my jquery code.

$.ajax({
                url: '/modal_edit_doctor/'+id,
                type: 'get',
                dataType: 'json',
                success: function(response){
                    console.log(response['data']);
                if(response == "success")
                  console.log(response['data']); 
                  $("#editdoctor").modal('show');
                  $("#url_generation").val(response['data'][0].url_generation);
                  $("#status").val(response['data'][0].status);
                  var objJSON = JSON.parse(response['data'][0].certificate);
                  console.log(objJSON);


                    $("#name").val(response['data'][0].name);
                    $("#alpha_name").val(response['data'][0].alphabet_name);
                    //image not included yet
                    $("#img_caption").val(response['data'][0].image_caption);
                    $("#img_alt").val(response['data'][0].image_alt);
                    //industry dropdown not included yet
                    //conference json not included yet
                    //birthday not included yet
                    $("#place_birth").val(response['data'][0].place_of_birth);
                    //the 3 careers not included yet
                    //checkbox not included yet
                    //hospital dropdown not included yet
                    //department json not included yet
                    $("#doc_comment").val(response['data'][0].doctor_comment);


                },
                    error: function(response){
                    alert('Error'+response);

                }

              });

2

Answers


  1. Loop through it objJSON and you will access the data. I think you want this.

    #textboxes is your text field id, maybe value or text you want to display.
    $.each(objJSON, function(key,value){
       $("#textboxes").text(value.med_sbj_list);
    });
    
    Login or Signup to reply.
  2. this will be like this i am not good at jquery but i’ll write EJS

    use this to get idea

    var certificate1 = document.getElementbyId(‘certificate1’)

    certificate1.innerHTML = <%=response.certificate[0].med_sbj_list %>

    you have to get the ceritificate row first as you can see the certificate row is an array so use it like array to access it.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search