Welcome Guest, Not a member yet? Register   Sign In
how to configure XAJAX 0.5 with codeigniter 1.6.1
#1

[eluser]Amit Patel[/eluser]
Hello all

I have codeigniter 1.6.1 version and xajax 0.5 version. I follow the process in wiki
for complete setup with "http://codeigniter.com/wiki/Xajax_perfect_setup/" but i can't success i got the following error

Code:
A PHP Error was encountered

Severity: Warning

Message: Cannot modify header information - headers already sent by (output started at C:\wamp\www\syncacross\system\application\controllers\admin\testxajax.php:2)

Filename: helpers/url_helper.php

Line Number: 487

I tried all the solution for codeigniter forum and other forum but still having the same problem my controller is

Code:
<?php

class Testxajax extends Controller
{

    function Testxajax()
    {
         parent::controller();
        
         $this->load->library('xajax');
        
         ini_set('display_errors',1);
        
         error_reporting(2039);
        
         if (!$this->session->userdata("admin"))
         {
            redirect("admin/admin/login");
         }
        
        $this->xajax->registerFunction(array('test_function',&$this,'test_function'));
    
        $this->xajax->processRequest();
    }
    
    function index()
    {
        $template['xajax_js'] = $this->xajax->getJavascript(base_url());
        
        //$template['xajax_js'] = $this->xajax->getJavascript('../../');
      
        $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"&gt;';
      
        $this->load->view('admin/template/index', $template);
    }
    
    function test_function($number)
    {
        $objResponse = new xajaxResponse();
        
        $objResponse->Assign("SomeElementId","innerHTML", "Xajax is working. Lets add: ".($number+3));
        
        return $objResponse;
    }
}
?&gt;

and view is

Code:
&lt;html&gt;
&lt;head&gt;
    &lt;title&gt;Xajax 0.5 test&lt;/title&gt;
    &lt;?=$xajax_js?&gt;
&lt;/head&gt;

&lt;body&gt;
  <h1>&lt;?=$content?&gt;</h1>
&lt;/body&gt;
&lt;/html&gt;
#2

[eluser]aroman[/eluser]
Hello Amit,
Welcome To CI..
Try to check in your testajax controller maybe you're sending a whitespace character..
Also try to turn on your error log, and see in the log file which files are loaded maybe one of those file is sending a whitespace character.

Code:
$config['log_threshold'] = 4;

In order to prevent some "Cannot modify headers problem ..." dont close your php tag.
Ex:
Code:
&lt;?php
// starts your code here ...
// more code here ...
?&gt; <-- no need the closing php tag, the compiler will take care of that.
Hope it helps.
-aroman
#3

[eluser]Amit Patel[/eluser]
Thanks aroman,

I tried above both solution make error log ON and also remove the php closing tag in controller but i got the same error like

"Output has already been sent to the browser at C:\wamp\www\syncacross\system\application\controllers\admin\testxajax.php:2. Please make sure the command $xajax->processRequest() is placed before this."

when i comment this line in above code than it's not giving me error and view is called succesfully but as soon as uncomment the following line the error start .

$this->xajax->registerFunction(array('test_function',&$this,'test_function'));

$this->xajax->processRequest();

I tried many times to configure xaxjx with CI in various way but same error i have getting
#4

[eluser]aroman[/eluser]
Btw, what CI version you are using right now ?

Ive encountered these error "Cannot modify header information.." in CI version 1.6.3 before. Then I check each file if ive missed a whitespace charcter but i havent even found one.
So what i did i try to suppress the error put @ symbol in the setcookie() inside Session.php library.
Ex.
Code:
@setcookie(
  $this->sess_cookie,
  $cookie_data,
  $this->sess_length + time(),
  $this->CI->config->item('cookie_path'),
  $this->CI->config->item('cookie_domain'),
  0
);
Then, my header problem is gone..
So, try to put @ symbol in yur setcookie( ) and hope it will works.

-aroman
#5

[eluser]Amit Patel[/eluser]
I am using CI version 1.6.3

I tried to put @ symbol in the setcookie() inside the session.php library though i get same error as soon as i disabled below two line for xajax code than it succesfully called the view but when i enabled the same error i got.

$this->xajax->registerFunction(array(‘test_function’,&$this,‘test_function’));

$this->xajax->processRequest();

I tried the to install xajax again but same result i am getting. Please can you repeat whole procedure for CI version 1.6.3 . I used wamp server in which php version is 5.2.4 and mysql version 5.0.45.


Thanks and regards,
---Amit Patel
#6

[eluser]aroman[/eluser]
Hello Amit,
Ive try to use your code above on my pc and it works well.. i think you have missed something in your xajax setup..
And how would you call the test_function() ?
I assumed to call the test_function is during onclick event of the button..
See my code below,,same as yours but jst a little tweak..
Code:
&lt;?php

class testajax extends Controller
{
    var $error = array( ) ;
    function testajax( )
    {
        parent::controller();
        $this->load->library('xajax');
        ini_set('display_errors',1);
        error_reporting(2039);
         // if (!$this->session->userdata("admin"))// i comment this bec, i dont have an admin side :)
         // {
            // redirect("admin/admin/login");
         // }
        $this->xajax->registerFunction(array('test_function',&$this,'test_function'));
        $this->xajax->processRequest();
    }
    
    function index()
        {
        // my xajax directory path
        $template['xajax_js'] = $this->xajax->getjavascript( base_url( ) . "js/xajax/" ) ;
        //$template['xajax_js'] = $this->xajax->getJavascript(base_url()); // before
        //$template['xajax_js'] = $this->xajax->getJavascript('../../');
        $template['content'] = '<div id="SomeElementId"></div>&lt;input type="button" value="test"  onclick="xajax_test_function(1)" &gt;';
        $this->load->view('admin/template/index', $template);
    }    
    
    function test_function($number)
        {
        $objResponse = new xajaxResponse();
        $objResponse->Assign("SomeElementId","innerHTML", "Xajax is working. Lets add: ".($number+3));
        return $objResponse;
        }    
}
I run these code above and the xajax response works well printed "Xajax is working. Lets add: 4"

-aroman
#7

[eluser]Amit Patel[/eluser]
Thanks aroman

As i finally installed new version of CI and find success to configure xajax. Now i want to submit a form

using xajax i search and found to use this function "xajax_processFormData(xajax.getFormValues('formId'))"

where formId is the id of the form. But it's not working. So if possible than give me one example of how to

submit form using xajax and get form values in controller function. Again thanks for your intrest to me.

waiting for your reply

Thanks and regards,
---Amit Patel
#8

[eluser]Unknown[/eluser]
Please submit your code, so we can explore your code and learn something from it.

Looking forward to see your code.
#9

[eluser]stoefln[/eluser]
hi i have a different question to the xajax pros:
is there a way that xajax calls the CI methods directly with the parameters which are needed?
kind of hard to explain, here is an example:
i have a controller "Users"
Code:
class Users extends Controller{
  function editdetails($userId,$formdata)
}
so when i submit an Ajax call from client side i have to do that like this:
Code:
xajax_editdetails(userId,formdata)

but where do i get the userId from? i could parse the request uri and pull it out, but there could be a more convenient way...
any ideas?

BR Steph




Theme © iAndrew 2016 - Forum software by © MyBB