Welcome Guest, Not a member yet? Register   Sign In
Setting csrf_regenerate as TRUE
#8

Thanks Martin for your help and giving some much needed confidence  Wink

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.
Reply


Messages In This Thread
Setting csrf_regenerate as TRUE - by june123 - 07-27-2017, 04:45 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-27-2017, 08:27 AM
RE: Setting csrf_regenerate as TRUE - by spjonez - 07-27-2017, 06:21 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 01:36 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 06:15 AM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-28-2017, 11:50 PM
RE: Setting csrf_regenerate as TRUE - by june123 - 07-31-2017, 12:19 AM



Theme © iAndrew 2016 - Forum software by © MyBB