'Some form fields not receiving a value after making an AJAX request

I want to edit a form but some of the values are not being filled after clicking on the edit button. I have shared the AJAX response and jQuery code. Can anyone help me resolve this problem?

enter image description here

Response:

[
  {
    "category": "2",
    "item_name": "21",
    "amount": "10000",
    "total_tax": "1800",
    "variation": "2",
    "rate": "10",
    "f_length": "1000",
    "nop": "5"
  }, {
    "category": "1",
    "item_name": "23",
    "amount": "40000",
    "total_tax": "7200",
    "variation": "2",
    "rate": "20",
    "f_length": "2000",
    "nop": "6"
  }
], 
"po_notes_details": [
  { "note_desc": "a" },
  { "note_desc": "a" },

$(document).on("click", ".edit_record", function() {
  var edit_id = $(this).data('purchase_id');

  $.ajax({
    type: 'POST',
    url: 'ajax_task.php',
    data: {
      edit_id: edit_id,
      purchase_edit: 'purchase_edit'
    },
    success: function(data) {
      var response = JSON.parse(data);
      $('#category').val(response.category);
      $('#item_name').val(response.item_name);
      $('#variation').val(response.variation);
      $('#rate').val(response.rate);
      $('#f_length').val(response.f_length);
      $('#terms_condition').val(response.terms_condition);
      $('#payment_terms').val(response.payment_terms);
      $('#purchase_name').val(response.purchase_name);
      $('#purchase_type').val(response.purchase_type);
      $('#purchase_data_iud').val(response.purchase_id);
      $('#purchase_date').val(response.purchase_date);
      $('#po_no').val(response.po_number);
      $('#po_cat').val(response.po_cat);
      $('#po_type').val(response.po_type);
      $('#effective_start_date').val(response.effective_start_date);
      $('#effective_end_date').val(response.effective_end_date);
      $('#mode_of_despatch').val(response.mode_of_despatch);
      $('#transportation_charges').val(response.transportation_charges);
      $('#insurance_charges').val(response.insurance_charges);
      $('#packing_charges').val(response.packing_charges);
      $('#project_lead_time').val(response.project_lead_time);
      $('#state').val(response.state);
      $('#vendor_quote_no').val(response.vendor_quote_no);
      $('#vendor_quote_date').val(response.vendor_quote_date);
      $('#installation_services_charges').val(response.install_and_service_charges);
      $('#other_charges').val(response.item_cost_oth_charges);
      $('#grand_total').val(response.grand_total);
      $('#grand_total_tax').val(response.grand_total_tax);
      $('#total_amount').val(response.total_amount);
      $('#purchase_data_iud').val(response.purchase_id);
    }
  });
});


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source