CodeIgniter and AJAX |
[eluser]Unknown[/eluser]
Hello! I just downloaded CodeIgniter few days ago and already love it. It will save you so much time in developing web apps. However, I'm having a trouble with making ajax requests. I've made an view for login and "forgot password" forms and the view looks like this: Note: Those action parts are written correctly, I just don't know why this will show them as they are seen in below. Code: <div id="wrapper"> Here I have my Controller for both of the methods, login and forgot password. Here's my controller: Code: <?php I won't post my model since I know it's already working. Here's my ajax code for that forgot_pass() - method: Code: $(document).ready(function() { Every time I'll press the forgot_pass() submit button, I'll always get that first exit() from the method saying "No post value". What I'm doing wrong and how should I implement the code to actually get the result 1 or 0 based on the condition if user's email address is actually found in the database. Thanks in advance ![]()
[eluser]Karman de Lange[/eluser]
Hi, 1: try not to use $_POST , Rather use $this->input->post() .. This helps with security 2: I did not read your code properly but to debug, just do a var_dump($this->input->post()); above your check if(empty($_POST['to_submit'])) and use firebug or similar to see the data sent/received. With firebug you can see the actual post values that was sent. L:
[eluser]LuckyFella73[/eluser]
Regarding your last question: Code: // call your model method and assign the return value to a variable: for you didn't provide your model code I can't edit that right now but I guess you are able to manage that.
[eluser]EyeAmN8[/eluser]
If you have csrf protect enebled in the config file, ajax requests will always fail for posts. In order to fix this you will need to pass the csrf token along with your post data. easiest way to do it is use codeiigniter's form helper, it will make one for you. Make sure that you either post that form or post the token from the form. There are other ways to get the token but that is the easiest to explain.
[eluser]Sanjay Sarvaiya[/eluser]
I think the problem at serialize form data. could you test without $ sign as bellowed. Code: $.ajax({ |
Welcome Guest, Not a member yet? Register Sign In |