Welcome Guest, Not a member yet? Register   Sign In
Ajax Framework (CJAX) for Codeigniter 2.x+

[eluser]gwatt[/eluser]
Hi,

There is no big rush. Now that I know I can write a function to build relative links I can start working.

I have hardly used CJAX yet so when I get some of system working using CJAX and understand how it works in CI I will definitely write a review.

This issue has confused me for a month so I don't want other people to have the same issue.
Any testing around this issue would be great. The easier it is to use in CI the better.

G

[eluser]Needle[/eluser]
Okay, I feel like I'm close to finally having this working, but a final hurdle still has me stumped. All of the provided CJAX examples are working for me. When I try to mimic the click_ajax_request example in my setup, I'm not getting a response.

I have a main controller
application/controllers/click_ajax_request.php

Code:
<?php
class click_ajax_request extends MY_Controller {

function index()
{
  $this->load->view('click_ajax_request');
}
}

This loads my view
application/views/click_ajax_request.php

Code:
<?php
$this->load->file(FCPATH.'ajaxfw.php');
$ajax = ajax();

$ajax->click("link1",$ajax->call("ajax.php?click_response/click_link/hello"));
?>

<html>
<head>
<meta http-equiv="Content-Type" c charset=utf-8">
<title>Simple ajax request binded to a link</title>
<?php echo $ajax->init();?>
</head>
<body>
<h2>Simple ajax request binded to a link</h2>
<a id="link1" href="#">Link 1</a>
<div id="response">
</div>
&lt;/body&gt;
&lt;/html&gt;

Which, upon clicking the link, is supposed to call my ajax controller
application/response/click_response.php

Code:
&lt;?php

class click_response {

function click_link($message)
{
  $ajax = ajax();
  
  $ajax->success("You clicked the link.. $message");
}
}

The view loads properly and it looks like Ajax is initializing properly with no errors in the inspector. Each time the link is clicked, the console prints:

_call waits : caller: set.event cjax-5.5.min.js:278
Call executed. cjax-5.5.min.js:377
Waiting for response..

but the response never comes. The Chrome Network tab reports a 200 Status GET request has been fired, with the path
http://dev.my-project:8888/ajax.php?click_response/click_button/hello

Any idea what I'm missing here? I can't seem to get the ajax response to come back, even though when I try the straight CJAX example it works fine.

Using: Codeigniter 2.1.4, AJAXFW 5.5

[eluser]Alexlv4[/eluser]
Hi

I am new using CJAX.

I want to propagate two dropdown dependent

empresa -> programa -> grupo

I try using this
Code:
$ajax->change("select_empresa",$ajax->call($ajax_relativa."ajax.php?tantum/programa_select/|select_empresa|"));

$ajax->change("select_programa",$ajax->call($ajax_relativa."ajax.php?tantum/grupo_select/|select_programa|"));

My controller in response folder is
Code:
function programa_select($selected)
{
  $ajax = ajax();
  $data = array();
  
  $programas = $this->membership_model->dame_programas_de_empresa($selected);
  
  for ($z = 0; $z < sizeof($programas); $z++) {
   $data[$programas[$z]['programa_id']] = $programas[$z]['programa_nombre'];
  }
  
  $ajax->select('select_programa',$data);
  
}

function grupo_select($selected)
{
  $ajax = ajax();
  $data = array();
  
  $grupos = $this->membership_model->dame_grupos_de_programa($selected);
  
  for ($z = 0; $z < sizeof($grupos); $z++) {
   $data[$grupos[$z]['grupo_id']] = $grupos[$z]['grupo_nombre'];
  }
  
  $ajax->select('select_grupo',$data);
  
}

But just the first works fine

it is posible?
What i am doing wrong?

Thanks in advance

[eluser]Alexlv4[/eluser]
Hi again.

Well I solve my problem.

I just add an option with value 0 and works fine

Code:
function programa_select($selected)
{
  $ajax = ajax();
  $data = array();
  
  $programas = $this->membership_model->dame_programas_de_empresa($selected);
  
  $data[0] = 'Selecciona un programa';
  $data_a[0] = 'Selecciona un grupo';
  for ($z = 0; $z < sizeof($programas); $z++) {
   $data[$programas[$z]['programa_id']] = $programas[$z]['programa_nombre'];
  }
  
  
  $ajax->select('select_programa',$data);
  $ajax->select('select_grupo',$data_a);
  
}

function grupo_select($selected)
{
  $ajax = ajax();
  $data = array();
  
  $grupos = $this->membership_model->dame_grupos_de_programa($selected);
  
  $data[0] = 'Selecciona un grupo';
  for ($z = 0; $z < sizeof($grupos); $z++) {
   $data[$grupos[$z]['grupo_id']] = $grupos[$z]['grupo_nombre'];
  }
  
  $ajax->select('select_grupo',$data);
  
}

Thanks for CJAX is awesome and easy to use

[eluser]Ajaxboy[/eluser]
For some reason I didn't receive the email to the subscribed thread so I wasn't aware of the questions.


@Alexlv4

Glad you got it working.



@needle

I am looking at the code now

[eluser]Ajaxboy[/eluser]
@needle

I was just made aware of a possible issue in some servers , At this point I am not sure what is producing it but it might be the version of php 5.3, not 100% sure. This issue some times prompts you to get a blank page.

If this is the same issues, here is the fix:

In file cjax/cjax.php line 36:

Change:
Code:
$file = preg_replace("/.+\//",'', $_SERVER['SCRIPT_NAME']);
to
Code:
$file = preg_replace("/.+\//",'',ltrim($_SERVER['SCRIPT_NAME'],'/'));

I believe this will take care of your issue.

[eluser]Needle[/eluser]
Yes, that cjax.php fix appears to have done it! Responses are now coming through as they should.

I can't tell you how pleased I am to finally have this working, I was beginning to think I was crazy! Thanks very much for your help Ajaxboy. CJAX looks like a fantastic framework and I will definitely leave a review once I've had a chance to play with it a bit more.


[eluser]Ajaxboy[/eluser]
[quote author="Fredrik-s" date="1377037588"]Hello,

I also encounter the problem with the "blank page".

My setup:
PHP Version 5.3.10-1ubuntu3.6
CodeIgniter 2.1.4
AJAXFW_4CI_5.5

Im running "clean URLs". I have followed the solution in this thread: http://ellislab.com/forums/viewthread/220620/#1016536

I get a "200 OK" when checking the network tab in Chrome. Im calling the following URL to test Cjax: http://mydomain.com/ajax/test/test

My file structure looks like this:
root
-.htaccess
-ajax.php
-ajaxfw.php
-application
--controllers
---AjaxController.php
--response
---sample.php
---test.php
-views
--test.php
--test2.php
-cjax

htaccess:
Code:
Options -Indexes
RewriteEngine on

RewriteRule  ^/?ajax/(.*)$ ajax.php?$1 [QSA,L]

RewriteCond $1 !^(index\.php|assets|font|bootstrap|cjax|robots\.txt|ajaxfw\.php|ajax\.php)

RewriteRule ^(.*)$ index.php/$1 [L]



I dont get any PHP errors in my error.log. And nothing displays when reaching http://mydomain.com/ajax/test/test just a blank page.

Not either any JS errors in console tab in Chrome.

What am I doing wrong and how should I fix it?
[/quote]

I above solution should also solve your problem.

This will be included in the next maintenance release.


@needle

Glad everything is working for you.




Theme © iAndrew 2016 - Forum software by © MyBB