AJAX with CodeIgniter and jQuery
So I ran into some stupid bugs and not-so-stupid bugs so I quickly wanted to share this with anyone who might see this, and to review what I learned today also.
Let me describe the page I'm building right now -
I'm building a website for an artist and that website has a backend where you can edit/upload pictures and their titles. For the edit section I have a grid of pictures that you can select in order to load their information into form elements. I want to do this with AJAX (using jQuery) so I make it send an AJAX request (probably not the right terminology but hopefully you know what I mean) to a CodeIgniter controller.
Now the first problem was my lack of understanding/realizing that there is going to be a problem sending data to/from CodeIgniter and jQuery. So basically there are helper functions for PHP and Javascript that facilitate with translating string<->JSON object. This is due to the fact that PHP can only pass a string as data to Javascript. We then convert that string-form JSON into a JSON object in Javascript by using jQuery's jQuery.parseJSON(). http://api.jquery.com/jQuery.parseJSON/
The code is pretty simple so I think I'll just post the code and it should be pretty clear how to do this. If not - definitely leave a comment and I'll reply ASAP if anyone actually needs help with this :)
http://snipt.net/ehdeelee/ajax-call-from-javascript
http://snipt.net/ehdeelee/ajax-receiver-from-codeigniter
snipt.net - is GREAT by the way. You should really check it out because the interface is just byoooootiful.













