Click here to Skip to main content
16,023,047 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I want to return requested data which included form elements with array name like name="desc[]" and so on when I echo result from php file it gives error "Notice: Array to string conversion", so how to overcome this issue? I am appending the response in table tbody onclick

What I have tried:

My ajax call

  $.ajax({
    type: "POST",
    url: "ajaxRequests/createVrEntriesRows.php",
    data: "form_data=" + form_data +"&rows=" + rows,
    success: function(response){

        $('#VR_Entries').append(response);

    }
});


My Php file

<?php 

  require_once '../controllers/conn.php'; 

		if(isset($_POST["form_data"])){

			extract($_POST);

			$parts = explode('/', $domain_class);

			$class = isset($parts[0])?$parts[0]:'';
			$sub_class = isset($parts[1])?$parts[1]:'';
			$domain = isset($parts[2])?$parts[2]:'';

			$sr_no = $_POST['rows']+1;

			return '<tr>
                    <td>
                        <input type="hidden" name="sr_no[]" value="'.$sr_no.'">'.$sr_no.'
                    </td>
                    <td>
                        <input type="hidden" name="job[]" value="'.$job.'">'.$job.'
                    </td>
                    <td>
                        <input type="hidden" name="account[]" value="'.$account.'">'.$account.'
                    </td>
                    <td>
                        <input type="hidden" name="class[]" value="'.$class.'">'.$class.'
                    </td>
                    <td>
                        <input type="hidden" name="sub_class[]" value="'.$sub_class.'">'.$sub_class.'
                    </td>
                    <td>
                        <input type="hidden" name="domain[]" value="'.$domain.'">'.$domain.'
                    </td>
                    <td>
                        <input type="hidden" name="desc[]" value="'.$description.'">'.$description.'
                    </td>
                    <td class="debit">
                        <input type="hidden" name="debit[]" value="'.$debit.'">'.$debit.'
                    </td>
                    <td class="credit">
                        <input type="hidden" name="credit[]" value="'.$credit.'">'.$credit.'
                    </td>
                     <td>
                        <button type="button" class="btn" onclick="DeleteRowFunction(this)">x</button>
                        <button type="button" class="btn">
                            
                        </button>
                     </td>
                  </tr>';
		}

?>
Posted
Updated 1-Oct-18 3:23am

1 solution

first of all never add html snippet inside php files , its not good for readability, reuse-ability and for debugging.

here you can create a separate view and call it on return method or you can add view in
json_encode
.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900