Thanks Martin for your help and giving some much needed confidence
But to be honest, I am not very good with this json/jquery stuff. Thats why I had to stitch up that weird json string. Now I have done this far:
Quote:foreach ($loop as $row)
{
$departments[] = array('id'=>$row['id'],'name'=>$row['name']);
}
$response['departments'] = $departments;
$response['csrfTokenName'] = $this->security->get_csrf_token_name();
$response['csrfTokenHash'] = $this->security->get_csrf_hash();
echo json_encode($response);
Then in ajax part:
Quote:$('#project_id').change(function() {
var project_id=$("#project_id").val();
var domain=$("#domain").val();
$.ajax({
type: "POST",
url: domain + "index.php/project/get_department",
data: {project_id: project_id},
dataType: 'json',
success:
function(j){
csfrData = {};
csfrData[j.csrfTokenName] = j.csrfTokenHash;
if(j.departments.length >=2) {
var options = '';
for (var i = 0; i < (j.departments.length-1); i++) {
options += '<option value="' + j.departments[i].id + '">' + j.departments[i].name + '</option>';
}
$("#department_id").html(options);
$('#department_id option:first').attr('selected', 'selected');
}
else if (j.departments.length == 1){
options += '<option value="' + j.departments[0].id + '">' + '------------------------------------' + '</option>';
$("#department_id").html(options);
$('#department_id option:first').attr('selected', 'selected');
}
else{
$("#department_id").val(j.departments[1].id);
}
}
});
});
Now the next combobox doesnt get populated:
Quote:$('#department_id').change(function() {
var department_id=$("#department_id").val();
var domain=$("#domain").val();
$.ajax({
type: "POST",
url: domain + "index.php/project/get_scheme",
data: {department_id: department_id},
dataType: 'json',
success:
When I checked the console in developer tools(chrome), the following msg comes:
Failed to load resource: the server responded with a status of 403 (Forbidden) get_scheme
Maybe the ajaxSetup function in csrf.js file is not sending the updated token:
$(function() {
// Attach csfr data token
$.ajaxSetup({
data: csfrData
});
});
Kindly guide.