Welcome Guest, Not a member yet? Register   Sign In
cjax not working when page loaded using cjax
#1

[eluser]saran12[/eluser]
Hi ,

i am new to code igniter i am trying to load and submit a form using ajax. in first page i have a link when click it loading using cjax and response will write in a div in that reponse i also try to use cjax form submit but it's not working for me can any one please help me.

(ex) list -> edit ->list
#2

[eluser]Ajaxboy[/eluser]
did you do init() in the head of the page?
#3

[eluser]saran12[/eluser]
Yes. here i attached my sample code

<?php
$this->ajax = ajax();
$this->ajax->Exec('user_guide',$this->ajax->call('ajax.php?welcome/index','container'),'click');
echo $this->ajax->init();
?&gt;<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
&lt;style type="text/css"&gt;
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;
&lt;?php if (!$this->ajax->isAjaxRequest()) {?&gt;
<div id="container">
&lt;?php } ?&gt;

<p>If you are exploring CodeIgniter for the very first time, you should start by reading the <a id="user_guide">User Guide</a>.</p>

<p class="footer">Page rendered in <strong>{elapsed_time}</strong> seconds</p>
&lt;?php if (!$this->ajax->isAjaxRequest()) {?&gt;
</div>
&lt;?php } ?&gt;


&lt;/body&gt;
&lt;/html&gt;
#4

[eluser]Ajaxboy[/eluser]
You got most of it right, except the "ajax controllers workflow"

Ajax controller are separate than regular controllers. It is not recommended to request the same index controller (unless you really know what you are doing) because you would be invoking all the media (css/js) stuff to load again and that can interfere with the application from working and also will make it slower.


try it more like this:

Code:
&lt;?php
//MAKE sure cjax is includes:
require_once 'ajafw.php'; // in 5.1 require_once 'ajax.php';

$this->ajax = ajax();

$this->ajax->Exec('user_guide',$this->ajax->call('ajax.php?welcome2/index_ajax','container');
?&gt;
<!DOCTYPE html>
&lt;html lang="en"&gt;
&lt;head&gt;
Code:
&lt;?php echo $this->ajax->init();?&gt;
&lt;style type=“text/css”&gt;
a {
color: #003399;
background-color: transparent;
font-weight: normal;
}
&lt;/style&gt;
&lt;/head&gt;
&lt;body&gt;

Code:
<div id='container'>
See <a id='user_guide'>User Guide</a> text.
</div>
&lt;/body&gt;
&lt;/html&gt;

The in application/response/welcome2.php

Code:
class Welcome2 extends CI_Controller {

function index_ajax {
echo "If you are exploring CodeIgniter for the very first time, you should start by reading the User Guide";
}

}

See creating controllers: http://cjax.sourceforge.net/docs/creatin...ollers.php
#5

[eluser]saran12[/eluser]
Thanks for your quick reply. in that response page shall i use cjax exec?. i need to load the pages with out reload full pages.
#6

[eluser]Ajaxboy[/eluser]
You are welcome,

Yes you can use Exec on the response page. If you download the samples package you will find lots of samples that show how the workflow operates. click() is a wrapper for exec click event.

Code:
class Welcome2 extends CI_Controller {

function index_ajax {
$ajax = ajax();

$ajax->click('link', $ajax->call('ajax.php?welcome2/other_method'));

echo "If you are exploring CodeIgniter for the very first time, you should start by reading  the User Guide";
}

}
#7

[eluser]saran12[/eluser]
class Welcome2 extends CI_Controller {
public function index_ajax() {
$ajax = ajax();
$ajax->click('link', $ajax->call('ajax.php?welcome/index'));
echo "If you are exploring CodeIgniter for the very first time, you should start by reading the <a id='link'>User Guide</a>";
}

}

Not working for me.
#8

[eluser]Ajaxboy[/eluser]
You must test your own environment, I can 't do that for you. Be sure to download the samples package to help you test https://sourceforge.net/projects/cjax/files/Demos/ . The code in the controller above is generic code and untested by me, you need to adjust it to work for you.




Theme © iAndrew 2016 - Forum software by © MyBB