Welcome Guest, Not a member yet? Register   Sign In
passing data from AJAX to Controller
#4

[eluser]Unknown[/eluser]
You should send your ajax request with POST as suggested by ivantcholakov.

If you consider using POST this method, you need to protect your controller with :

Code:
if ($this->input->is_ajax_request())
{
   // code
}
else
{
    die("No direct access allowed, go eat some bacon");
}

Secondly, if you are using the csrf protection of CodeIgniter, you need to add your CSRF Token to your post data.
In config/config.php you have section about it.

Just send your token name and your key with your post data.

Code:
function loadVisaStatusFn()
{
var cs_vx_no = $('#cs_vx_no').val();
var cs_passport = $('#cs_passport').val();    
var tcs_fname = $('#tcs_fname').val();  
var tcs_passport = $('#tcs_passport').val();

$.ajax({
  type: "POST",
  url: '<?php echo site_url('ajax/getVisaStatus'); ?>',
  data: {
    cs_vx_no : cs_vx_no,
    cs_passport : cs_passport,
    tcs_fname : tcs_fname,
    tcs_passport : tcs_passport,
    csrf_token_name: "<?= $this->security->get_csrf_hash(); ?>" /* in the future of codeigniter it'll be unecessary with uri exclusions */
  },
  success: function(r){
   handleErrorFn(r);
   $("#rp-holder").html(r);
  }
});
}


Messages In This Thread
passing data from AJAX to Controller - by El Forum - 11-08-2013, 02:57 AM
passing data from AJAX to Controller - by El Forum - 11-08-2013, 04:41 AM
passing data from AJAX to Controller - by El Forum - 11-08-2013, 06:53 AM
passing data from AJAX to Controller - by El Forum - 11-08-2013, 03:46 PM
passing data from AJAX to Controller - by El Forum - 11-10-2013, 06:54 PM
passing data from AJAX to Controller - by El Forum - 11-10-2013, 08:22 PM



Theme © iAndrew 2016 - Forum software by © MyBB