Hi, I’m trying to pass the data in the Modal. So when I click the button it will get the post names of the form then go through ajax to pass the data. Here’s my controller:
public function getPatientRecords(){
$valuedID = $_POST['allpatientID'];
echo json_encode ($valuedID);
}
The Ajax Code:
function calAllRecords(){
$.ajax({
type: "post",
url: "http://ospar.hostzi.com/authorized/getPatientRecords",
cache: false,
data: $('#getAllRecords').serialize(),
success: function(json){
try{
var obj = jQuery.parseJSON(json);
$("#allpatient").modal("show")
}catch(e) {
alert('Exception while request..');
}
},
error: function(){
alert('Error while request..');
}
});
}
This is my view where the values of my id is hidden in the input fields:
if( !empty($allpatient) ) {
foreach($allpatient as $row){
echo '<form role="form" id="getAllRecords" action="http://ospar.hostzi.com/authorized/getPatientRecords">';
echo '<input type="hidden" name="allpatientID" value="'.$row->ID.'">';
echo '<td><p type="button" class="btn btn-info btn-lg" value="Submit" onclick="javascript:calAllRecords();">Open</p></td>';
}
}
Now when I click the button, I want the value to show in the modal so this is my modal body:
echo '<div class="modal-body">';
echo '<div class="table-responsive">';
echo '<table class="table table-bordered">';
echo '<tbody>';
echo '<tr>';
echo '<th scope="row">Firstname: </th>' . '<td>'. $valuedID .'</td>';
echo '</tr>';
echo '</tbody>';
echo '</table>';
echo '</div>';
echo '<p>Some text in the modal.</p>';
echo '</div>';
but I’m getting an error of:
Message: Undefined variable: valuedID
Please help me. Thanks