I have 2 ajax calls the first one that executes on change of #recipeName works but the second one(#resourceName) does not work. It seems it's not even going to my controller.
Javascript
<script type="text/javascript">
$(document).ready(function (){
$('#recipeName').change(function (){
var recId = $(this).val();
console.log(recId);
$.ajax({
url: "<?php echo base_url(); ?>" + "index.php/MainController/recipeDetails",
async: false,
type: "POST",
data: "name="+recId,
dataType: "json",
success:(function(data) {
$('#makes').val(data[0]);
$('#type').val(data[1]);
console.log(data);
})
})
});
$('#resourceName').change(function (){
var resId = $(this).val();
console.log(resId);
$.ajax({
url: "<?php echo base_url(); ?>" + "index.php/MainController/resourceDetails",
async: false,
type: "POST",
data: "resource="+resId,
dataType: "json",
success:(function(data) {
$('#rate').val(data[0]);
$('#per').val(data[1]);
console.log(data);})
})
});
});
</script>
HTML
<select name="resourceName" id="resourceName" required>
<option>Choose a resource</option>
<?php if($resources != null){
foreach($resources as $res){ ?>
<option><?php echo $res->resource;?></option>
<?php }}?>
</select>
My controller code is below. I even try to echo something out to see if the value gets passed to the controller but it doesn't echo anything.
public function resourceDetails() {
$resource = $_POST['resource'];
echo $resource . ' soe';
$result = $this->MainModel->resourceDetails(trim($resource));
if(isset($result)) {
$rate = $result->rate;
$per = $result->per;
$values = array();
$values[0] = $rate;
$values[1] = $per;
echo json_encode($values);
}
}