This question already has an answer here:
- processing $_POST in codeigniter 3 answers
View:
<table>
<tr>
<td id="percentage">Percentage: <?php echo $percentage; ?> %</td>
</tr>
</table>
<div class="box-footer" style="float: right">
<a href="<?php echo base_url(); ?>student/Examinations" class="btn btn-primary" style="font-size: 20px;" id="submit">Submit</a>
</div>
<script>
$(document).ready(function () {
var percentage = $("#percentage").text();
console.log(percentage); //Percentage: 28.57 %
$("#submit").click(function () {
$.ajax({
type: 'POST',
url: base_url + "student/Examinations",
data: {percentage: percentage},
success: function () {
}
});
});
});
</script>
Controller:
class Examinations extends CI_Controller {
function __construct() {
parent::__construct();
}
public function index() {
$percentage = $_POST["percentage"];
var_dump($percentage); // var_dump null
}
}
MY Question: javascript variable(percentage) to pass controller , and var_dump is null why?please help me.....................................
</div>