• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
What do you do for ajax requests?


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?

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.

Alright, thanks. Smile This clears things up for me.

[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


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

$this->data['xajax_js'] = $this->xajax->getjavascript(null, base_url().'public/javascript/xajax.js');

And the function (inside the controller)

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

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

[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!

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?


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

then, load like this


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

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

Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  

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