Welcome Guest, Not a member yet? Register   Sign In
using ajax
#1

[eluser]Unknown[/eluser]
how to use ajax with codeigniter?
#2

[eluser]Thorpe Obazee[/eluser]
It's PHP. It works the same way with or without CI.
#3

[eluser]pedro_sland[/eluser]
There is no built-in recommended way. I have tried a few ways but have found it depends on what sort of ajax you are doing. If its to get or set a lot of data instead of html then I create a new method or even controller for it. If its to compliment the html and the action is the same, then I create it in the same method and just use an if to test for ajax to decide whether to load a view or return json.
#4

[eluser]jdfwarrior[/eluser]
[quote author="bargainph" date="1241516717"]It's PHP. It works the same way with or without CI.[/quote]

+1.

CodeIgniter is nothing but a framework. It's still just PHP/HTML/CSS in the end. Whatever way you did ajax before.. It's done the exact same way with CodeIgniter.
#5

[eluser]Jagar[/eluser]
I use xajax toolkit, it's really good and works great. www.xajaxproject.org.

Download the toolkit and put it in the application/libraries/xajax and whenever you want to load it you just do
$this->load->library('xajax'); it depends where it is located, so you may have to change it.

You don't do any javascript stuff, all that is generated by xajax. You should try it.
#6

[eluser]jdfwarrior[/eluser]
jquery ftw.
#7

[eluser]Jagar[/eluser]
Yea Jquery is amazing as well, I'm currently learning that, and it's amazing what you can do with it.
#8

[eluser]sl3dg3hamm3r[/eluser]
[quote author="Jagar" date="1241549091"]Download the toolkit and put it in the application/libraries/xajax and whenever you want to load it you just do
$this->load->library('xajax'); it depends where it is located, so you may have to change it.[/quote]

Hey there

I have troubles loading this library. I renamed xajax.inc.php into xajax.php. When I do

$this->load->library('xajax/xajax');

I would get a:
Fatal error: Cannot redeclare class xajax in [...]\system\application\libraries\xajax\xajax.php on line 59

What am I doing wrong?

Oliver
#9

[eluser]Jagar[/eluser]
When you get that error message, means you are loading it in two places, make sure you have not declared anywhere else, that's how I got mine working.
#10

[eluser]sl3dg3hamm3r[/eluser]
Basically I only tried the small example-snippet which I found somewhere here in the forum:

Code:
function index() {
    
  function test_function($number) {
    $objResponse = new xajaxResponse();
    $objResponse->assign("hello","value", "Xajax is working. Lets add: ".($number+3));
    return $objResponse;
  }

  $this->load->library('xajax/xajax');    
  $this->xajax->registerFunction("test_function");    
  $this->xajax->processRequest();
  $template['xajax_js'] = $this->xajax->getjavascript('../../');
  $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"&gt;';
  $this->load->view('template', $template);
}

I don't call this class somewhere else...




Theme © iAndrew 2016 - Forum software by © MyBB