Really Need Help Understanding The Input Class for GET/POST Request |
[eluser]Unknown[/eluser]
Hello CI community. I've been struggling with this piece of code where I make an ajax call from the view to the controller to pass form data for validation and to save to session. That part works. Not how I want it to, but it works. The issue is that the ellislab documentation says that I should be able to access key values (whether get or post) by $this->input->post('key') or $this->input->get('key'). For the one that works, when I do a post request I have to loop through all of the keys. View: Code: jQuery(function ($) { Controller: Code: if ($this->input->post()){ But if I do $this->input->post('form_field_name'), I get nothing..(?) The one that doesn't work is the get request for the ajax call. View: Code: function previousForm(){ Controller: Code: if ($this->input->get('name')) And with the above get request, I get nothing returned and echoed. It's very confusing. I appreciate any response.
[eluser]Ckirk[/eluser]
In your example that doesn't work the following is invalid json: Code: { name: "previousform" } it should be: Code: { "name": "previousform" } Could that be your issue?
[eluser]Unknown[/eluser]
Thanks for responding. That's not the issue though. If you think the way I have it written should work, then it's probably something else.
[eluser]Rolly1971[/eluser]
the $this->input->post() is empty because you are sending the data using the get method. not post. Code: $('form_id_here').submit(function( event ) { the above is the basic method i use for ajax with CI. seems to work just fine. check jquery's doc's at the link below for info on the $.post and $.ajax methods: http://api.jquery.com/jQuery.post/ |
Welcome Guest, Not a member yet? Register Sign In |