I am using basic PHP & AJAX and I want to post data that i have selected from mysql database to a link online and fetch the response sent back to be used in update other information. I am using AJAX to post the data, but i cannot fetch the data sent back to use to update information.
Is it possible to just use PHP directly? how can it be done? What is the best way ?
Code:
$sql = $conn->query("SELECT * FROM hospitals");
if($sql){
    // $json_array = array();
    while($row = $sql->fetch_assoc()){
$output = '{"h_code": "' . $row['h_code'] . '", "h_name": "' . $row['h_name'] . '"}';
?>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
<script type="text/javascript">
    $.ajax({
            url: 'http://example.com/api/link',
            method: 'POST',
            data: <?php echo $output; ?>,
            success: function(data){
                console.log(data);
            }
        });
</script>
<?php
    $update = $conn->query("UPDATE hospital SET h_online_id=  ");
}
}
the response from AJAX call 'data' returns value from online database which i want to update a column from in the local database.
 
    