ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Ajax Framework (CJAX) for Codeigniter 2.x+

April 29, 2012 11:33am

Subscribe [24]
  • #196 / Sep 02, 2013 9:05am

    Ajaxboy

    243 posts

    Your issue really has nothing to do with Cjax, and more with basic url handling of the URL helper. What I said above was from the top of my mind, but I can’t really confirm the functions above since I am unable to test at this moment and is outside of the scope of Cjax. So I’d take it you need to look more into how CI handles the URL.

  • #197 / Sep 02, 2013 10:10pm

    gwatt

    9 posts

    Hi,

    It just returns a string based on site settings.

    I’m not saying there is an CJAX bug but my question is this…

    Why does calling this CJAX link
    uebusaito.com/engproj/ajax.php?controller/function/

    from this URL
    uebusaito.com/engproj/index.php/controller/function/

    result in a crossdomain request that doesn’t work?

    Surely CJAX should recognise that it’s the same domain: uebusaito.com

    This has nothing to do with the Code Igniter functions because they return the same thing.

    I’m not sure if this only doesn’t work for Code Igniter URLs but my point is for “CJAX for Code Igniter” to be fully compatible with Code Igniter it should work with Code Igniter URLS without having to write special functions to encode the URLs relatively.

    Otherwise there should be something in the documentation that warns people that it is not fully compatible with Code Igniter URLs. I’m only saying this because it is called “CJAX for Code Igniter” and so I assumed that this would work.

    I know you are doing this for free and I saw somewhere that you wanted people to help with documentation. I would be willing to help with this if I knew more about what was going on.

    It’s maybe not a bug but for Code Igniter I feel like this is a really basic thing that should work “out of the box”...

    G

  • #198 / Sep 02, 2013 11:09pm

    Ajaxboy

    243 posts

    I think it has to do with the server response?. Some servers monitor how a request is made and limit “none” regular browser requests. Ajax is meant to be used locally/relative not across domains. The fact that cjax allows to retrieve data from across domains, is a unique feature that no other Ajax application allows.

    However you should try to use a relative url when using ajax, it is just common practice, some times there are issues when using the full url in ajax.

    I assume, you are using source forge as host? since that is what was displayed on the request earlier. They do have that limitation and not allow remote requests. But I do see how someone’s intention to want to enter an absolute url for a local ajax request, the problem with this is that is not consistent and some browsers/servers have limitations with this action and that is why is treaty as an entire “foreign” url, however I see how someone would want to do that if they chooses to and their host allows it, in a future version I will introduce a setting where you can allow local request with full url for anyone who wants to do that. Though, it was avoided for a reason.

  • #199 / Sep 03, 2013 9:21am

    gwatt

    9 posts

    OK, I see.

    My site is hosted on shared virtual setup with Globat.com.

    It has been good and completely like a dedicated server so far nothing strange.

    I have a local “instance” of the server and php settings that I can change if there is something I can do there.

    I have no idea where the sourceforge stuff is coming from. I have nothing on my server and nothing in my code relating to sourceforge. I thought that CJAX was creating that from somewhere.

    If I call
    http://uebusaito.com/engproj/ajax.php?controller/function

    Then open the created crossdomain link it shows a page that looks like sourceforge (but the URL is the crossdomain link)

    I can’t imagine why it would do this.. the crossdomain link is being created by CJAX…

    G

  • #200 / Sep 03, 2013 10:16am

    Ajaxboy

    243 posts

    If I could test I would look a way around for you but like I mentioned I don’t have a development environment at my disposal right now - so any changes I make outside my development environment would not be available to anyone in a future release. Besides this I do have a server online but I will only do extra work for you if you commit to leave a review, as requested in one of the posts above.

  • #201 / Sep 03, 2013 9:02pm

    gwatt

    9 posts

    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

  • #202 / Sep 07, 2013 6:55pm

    Needle

    12 posts

    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

    <?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

    <?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>
    <p><a href="#id=link1">Link 1</a><br />
    <div id="response"><br />
    </div><br />
    </body><br />
    </html>

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

    <?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

     

  • #203 / Sep 11, 2013 1:11am

    Alexlv4

    2 posts

    Hi

    I am new using CJAX.

    I want to propagate two dropdown dependent

    empresa -> programa -> grupo

    I try using this

    $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

    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

  • #204 / Sep 11, 2013 10:34am

    Alexlv4

    2 posts

    Hi again.

    Well I solve my problem.

    I just add an option with value 0 and works fine

    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

  • #205 / Sep 14, 2013 4:09am

    Ajaxboy

    243 posts

    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

     

  • #206 / Sep 16, 2013 2:38am

    Ajaxboy

    243 posts

    @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:
    $file = preg_replace(”/.+\//”,’‘, $_SERVER[‘SCRIPT_NAME’]);
    to
    $file = preg_replace(”/.+\//”,’‘,ltrim($_SERVER[‘SCRIPT_NAME’],’/’));

    I believe this will take care of your issue.

  • #207 / Sep 17, 2013 11:48am

    Needle

    12 posts

    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.

  • #208 / Sep 17, 2013 4:21pm

    Ajaxboy

    243 posts

    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:

    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?

    I above solution should also solve your problem.

    This will be included in the next maintenance release.


    @Needle

    Glad everything is working for you.

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases