Home » Jquery » javascript – How to append Ajax response to div in html-Exceptionshub

javascript – How to append Ajax response to div in html-Exceptionshub

Posted by: admin February 24, 2020 Leave a comment

Questions:

this is my template:HTML TEMPLATE

This is my ajax Code

 $(document).ready(function(){
         $('.credit,.debit').change(function(){
            var value=$(this).val();
            $.ajax({
                type:"POST",
                url:"<?php echo base_url();>
index.php/Transactions/getamountbyid",
                    data:{id:value},
                success:function(result){
                    console.log(result);
                $(".bal").html(result);
            }
         });
         });
         });




This is my controller Code


public function getamountbyid(){
         $id=$this->input->post('id');
$this->Transaction_model->getamountbyid($id);
print_r($data1);
    }

And THIS is my Ajax Response

Array ( [0] => stdClass Object ( [Accounts_id] => 1 [Accounts_number] => 123123123 [Account_Name] => Qualight [account_nickname] => Qualight [Address] => hyderabad [Mobile] => 9123912345 [account_type] => 1 [PAN_NO] => 1231231231 [GST_NO] => 123 [credit] => 20000.00 [debit] => [balance] => 20000.00 [Time_stamp] => 2020-02-13 18:51:49 ) )

I want to display account debit and credit balance after selecting the account from drop down
it should be display below drop down can you please tell me how to append required response data to required field or div

How to&Answer: