CodeIgniter Forums
What do you do for ajax requests? - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forum-20.html)
+--- Forum: Archived Development & Programming (https://forum.codeigniter.com/forum-23.html)
+--- Thread: What do you do for ajax requests? (/thread-3438.html)

Pages: 1 2


What do you do for ajax requests? - El Forum - 10-01-2007

[eluser]IanMcQ[/eluser]
Hi,

I'm developing a new website using CI and I've come across some spots were it would be realllly nice to use some AJAX. How do you guys normally do AJAX requests within the CI library? I know how to do a request via javascript, but where do you normally put your PHP files that handle the AJAX requests? Just... create another controller? Or what?


What do you do for ajax requests? - El Forum - 10-01-2007

[eluser]Crafter[/eluser]
I'm not really sure what you're asking, but AJAX processing on browsers has nothing to do with server side processing.

If you are asking how the Ajax calls are handled, then my response is that this should be handled normally, without any special need for seperate controllers.

For example, I may have a controller called users, with a login method.

I would therefor code my application to render either a full page (with HTML headers), or a partial page, without HTML headers. There are many ways I could do this, for example:
- change the URL - http://mydomain.com/users/login vs http://mydomain.com/users/login/show_partial
- create new method - http://mydomain.com/users/show_login vv http://mydomain.com/users/show_login_partial

Ultimatey, I could use my existing controllers.


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]IanMcQ[/eluser]
Alright, thanks. Smile This clears things up for me.


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]James Spibey[/eluser]
I use a separate controller for ajax requests which shows the same view for each request and the data in that view is displayed as JSON enabling it to be easily parsed back on the client. Works very nicely but remember to disable to profiler for that page or it will break the JSON.

Oh, and on the client I use Prototype


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]ELRafael[/eluser]
Hum...

In my projects, i'm using XAJAX. Simple and funcionall. The functions are inside the controller. No problem.

Some pages, i'm using prototype and scriptaculuos. But just for cool efects, nothing more. XAJAX and CI comunicates very well. Just a little code

Code:
$this->load->library('xajax');
$this->xajax->registerFunction(array('eventos_editar',&$this,'eventos_editar'));
$this->xajax->processRequests();
$this->data['xajax_js'] = $this->xajax->getjavascript(null, base_url().'public/javascript/xajax.js');

And the function (inside the controller)

Code:
function eventos_editar($_id = FALSE)
{
    $xajax = new xajaxResponse();
    $output = 'daria um filme, uma negra e uma criança nos braços, solitária na flo';
    $xajax->addAssign('eventos', 'innerHTML', $output);
            
    return $xajax->getXML();
}

Adesso this Tongue


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]IanMcQ[/eluser]
How'd you get XAJAX to run in CodeIgniter (e.g., run it as a library)?


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]ELRafael[/eluser]
[quote author="IanMcQ" date="1191373686"]How'd you get XAJAX to run in CodeIgniter (e.g., run it as a library)?[/quote]

sorry man! but this is top secret!!!

but you looks like a good person! so, if you promisse that you never tell this, i'll pass to you this link http://codeigniter.com/wiki/XAJAX/

keep secret!


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]IanMcQ[/eluser]
That page says it's obsolete. And, it is. It's directions are for a previous version of XAJAX and CI. Any ideas on how to do it for an up to date version of CI?


What do you do for ajax requests? - El Forum - 10-02-2007

[eluser]ELRafael[/eluser]
Allright....

Put the xajax.php and other files in application/libraries

then, load like this

Code:
$this->load->library('xajax');

the rest is the same... registerFunction(), addAssign()...

if is obsolete i don't know, but to me is working!!!

you can use AJAX in Scriptaculous and Prototype if don't like xajax. I'm saying xajax cause i'm using this :-P


What do you do for ajax requests? - El Forum - 10-17-2007

[eluser]FuzzyJared[/eluser]
Hmmm -

I am trying to get xajax integrated with ci, and am running into a couple of issues. When I follow the instruction on the Wiki, and I believe that I have followed them, I get a couple of errors. If I put everything in place as in one of the examples on the wiki I get an some kind of critical error that stops all page output when I call..

Edited - found solution see later post