JQuery post parameters do not get to my controller |
Hi All,
I know this sounds like very similar issues already reported, but none of the solutions seems to work for me. The parameters passed from my JQuery post (or Ajax) do not get to my controller. I'm passing the csrf code, and also tried to disable it, but same issue. I am fairly new to codeigniter and think I am missing something basic, but I need some guidance. My controller is very simple: function __construct() { parent::__construct(); $this->load->helper('form'); $this->load->helper('html'); $this->load->model('users_model'); $this->load->library('form_validation'); parse_str($_SERVER['QUERY_STRING'],$_POST); } function create() { var_dump($_POST); $this->form_validation->set_rules('new_loc_loc_name', 'Address', 'required|urldecode'); if ($this->form_validation->run() == TRUE) { $this->users_model->filter_create(); } else { $this->load->view('filters/test'); } } And my view also very simple: <html> <head> <script src="/asset/js/external/jquery-1.11.2.js"></script> <link rel="stylesheet" href="/asset/css/external/1.11.3-jquery-ui.css" /> <script src="/asset/js/external/jquery-ui-1.11.3.js"></script> </head> <body> <?= form_open('user_filters/create', array('id' => 'form_id')); ?> <table class="main-dialog-table"> <tr> <td><label for="location">Location</label></td> <td> <input class="form_field_input" type="text" name="new_loc_loc_name" id="new_loc_loc_name"/> </td> </tr> <tr> <td> <input type="button" value="Create" id="new_loc_add" /> </td> </tr> </table> </form> </body> <script type="text/javascript"> $(document).ready(function(){ $('#new_loc_add').click( function() { var url = $("#form_id").attr('action'); $.post(url,$("form#form_id").serialize()); }); }); </script> </html> Looking at the Network tab (using chrome), I can see the post request finished successfully: Request URL:http://localhost/index.php/user_filters/create Request MethodOST Status Code:200 OK And the parameters passed seems to be correct: csrf_test_name:af1ff53c0eef00ea08cc4407d978822c new_loc_loc_name:aa Further more, if I will submit the following from the browser, I can see the parameters going through: http://localhost/index.php/user_filters/create?name=aa Any help would be appreciated. Thanks in advance. |
Welcome Guest, Not a member yet? Register Sign In |