CodeIgniter + jQuery UI autocomplete = 500 internal server error (with code) due to CSRF set to TRUE
Nothing in your question suggests that you need to turn query_strings
on or allow_get_array
Try this
comment out this line
$search = $this->input->post('term');
then add $search
to your function as the first argument
public function ac2($search)
Then just try to hit the URL with a browser
http://yourdomain.com/index.php/test/ac2/<insert your search string here>
Now that we know your url is good
change your controller back.
try this...
data: 'term='+req, //<-- change to this
seems you are missing sendig the csrf token with the POST data, try:
$("#input").autocomplete({ source: function(req, add){ var cct = $("input[name=ci_csrf_token]").val(); // <--- $.ajax({ url: '<?php echo base_url(); ?>test/ac2', dataType: 'json', type: 'POST', //data: req, data: 'input='+req, 'ci_csrf_token': cct, // <--- success: function(data){ if(data.response =='true'){ add(data.message); } } }); }, minLength: 2, select: function(event, ui){ $(this).end().val(ui.item.value); } }); });
you can also find the token like:
csrf_test_name:$("input[name=csrf_test_name]").val(),
that token is generated in the view when using the form helper and opening it like:
<?php echo form_open();?>
sources: * http://codeigniter.com/forums/viewthread/176318/** own headache