CI Beginner AJAX Question.

#1
[eluser]WoolyG[/eluser]
Hi all,

I need to use AJAX for my app, but I'm new to CI and would like some simple help on getting it going. I have searched the forums, but can't find anything of value.

Here's what I've done thus far:
1. Downloaded the AJAX Library (http://codeigniter.com/wiki/AJAX_for_CodeIgniter/)
2. Placed the Ajax.php into application/libraries (is this the right place?)
3. Placed the JS files into their own directory and linked to them from the HTML doc
4. Autoloaded the ajax library:

Autoload.php
Code:
$autoload['libraries'] = array('database', 'ajax');


Now come the questions:
a. How do I make an AJAX call by clicking on (say) a link?
b. I'd like the results to go to a DIV, how do I point to the div I'd like to use?
c. Within the AJAX data, I need to get dynamic data from the DB. How do I do that from within the ajax-called data?

In the case of ( c. ), usually within the file that is called, a new connection to the DB is made so that the AJAX file can make its own DB call. This is all doable using raw PHP, but I'd like to keep to the MVC model, so can anyone tell me how it's done in CI?

If someone could take the time to help me out I would be very grateful.

All the best,
WoolyG

#2
[eluser]WoolyG[/eluser]
*Bump* Smile
Anyone got an idea? - WoolyG

#3
[eluser]sqwk[/eluser]
Give jQuery a shot: http://jquery.com/

AJAX has nothing to do with CI. (Although CI 2.0 includes a javascript library, but I am not sure whether it is ready yet.) Just place the jquery file inside your webroot and link to it from your html head. (Has to be accessible by the client.)

Read up on Ajax use here: http://api.jquery.com/jQuery.ajax/

EDIT: I'd use CI to create a JSON or XML document that can be read in by jquery.


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


Users browsing this thread:
1 Guest(s)


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.