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]
  • #166 / Jul 11, 2013 3:35pm

    Ajaxboy

    243 posts

    Hello fran-quero,

    Thanks so much for the compliment, I really appreciate it.

    There is a select function in $ajax->select() that allows to deal with dropdowns/select elements. To fill ‘select’ elements. You just supply an array. Please see these samples:

    http://cjax.sourceforge.net/examples/propagate_dropdown.php

    http://cjax.sourceforge.net/examples/propagate_dropdown.php


    This is how it would propagate data into select elements:

    //Sample1
    $data = array('key' => 'value', 'key2' => 'value2');
    
    $ajax->select('zip',$data);  
    
    
    //Sample2   will show value2 as selected default
    $ajax->select('select1',$data, 'key2');


    On third parameter, you specify which item should be the selected default.


    Hope this helps, and do let me know if you run into any issues.


    May I ask for a favor?, can you please post your review here: https://sourceforge.net/projects/cjax/reviews/
    I will appreciate it even more, thanks!.


    Update:
    There are usually more than one way to accomplish things with Cjax, glad you found a solution.


    Ajaxboy

  • #167 / Jul 11, 2013 3:56pm

    fran-quero

    19 posts

    Thank you for the select info, I’ll check it out. I have to go deeper in the documentation.

    Just made my review in Sourforge!

    Now I have new question. With this code I show a modal if an identification id exists in a database table:

    $ajax->Exec('id', $ajax->overlay(base_url().'ajax/newuser/checkid/|id|'), 'blur');

    It works, but I’d like it to JUST show the modal if the id is found. When an id is not found cAjax shows an empty modal. Is that possible?

     

  • #168 / Jul 12, 2013 1:25am

    Ajaxboy

    243 posts

    Not too sure without knowing the full scope but generally speaking, when you pull the data from the database, you might want to add a check, for example:

    if ($id)  {
         $ajax->Exec('id', $ajax->overlay(base_url().'ajax/newuser/checkid/|id|'), 'blur'); 
    
    }
  • #169 / Jul 12, 2013 3:14pm

    fran-quero

    19 posts

    It’s an alert based on the value introduced by the user, so I can’t use if(), because, I search the id in the database once the input field for id loses focus. And this way, although the controller response is empty, $ajax->overlay() shows an empty modal.

    I’ll look for alternative ways.

    Thank you for your answer.

  • #170 / Jul 17, 2013 5:26pm

    salvomil

    17 posts

    Hi Ajaxboy,

    Could you help me please?

    How do I execute a synchronous call using cjax?

  • #171 / Jul 18, 2013 3:17pm

    fran-quero

    19 posts

    Hello. Give me a hand with this, please.

    I’m trying to use $this->input->post in my ajax controller (application/response/controller), but I always get undefined.

    $ajax->alert($form_fields['name']); //print value successfully
    $ajax->alert($this->input->post('a[name]')); //print undefined
    $ajax->alert($this->input->post($form_fields['name'])); //print undefined

    Can’t I use input->post in the ajax controller?

  • #172 / Jul 21, 2013 6:04pm

    Ajaxboy

    243 posts

    are you submitting a form with cjax?, if so you should be able to get the values in the $_POST variable or $this->input->post,  are you monitoring the ajax requests? if so make sure it’s using post.

  • #173 / Jul 24, 2013 7:15pm

    fran-quero

    19 posts

    That is what I’m doing:

    1) /application/controllers/customers.php

    public function new_customer()
    {
         $this->load->helper('form');
         
          $this->data['nombre'] = array(
                                        'name' => 'a[name]',
                                        'id'   => 'name',
                                        'type' => 'text',
                                );
                                $this->data['lastname'] = array(
                                        'name' => 'a[lastname]',
                                        'id'   => 'lastname',
                                        'type' => 'text',
                                );
    
      $this->load->file(FCPATH.'ajaxfw.php');
      $ajax = ajax();
      $ajax->sendButton = $ajax->form(base_url().'ajax/newcustomer/validateNewCustomer');
      load_view('v_newCustomer', $this->data);

    2) /views/v_newCustomer.php
    (script tag bad spelled to avoid it being removed)

    <scrip defer='defer' id='cjax_lib' type='text/javascript' src='<?php echo base_url();?>/cjax/core/js/cjax-5.5.min.js'></scrip>
    
    <?php echo form_open("");?>
    
    
                    name: 
                    <?php echo form_input($name);?>
                    
                        
                          Last name:
                          <?php echo form_input($lastname);?>
                    
    
    <?php echo form_submit('submit', 'New customer','id="sendButton"');?>
          
    <?php echo form_close();?>

    3) /response/newcustomer/validateNewCustomer.php

    $ajax = ajax();
    $ajax->alert($form_fields['name']); //print value successfully
    $ajax->alert($this->input->post('a[name]')); //print undefined
    $ajax->alert($this->input->post($form_fields['name'])); //print undefined
  • #174 / Jul 26, 2013 4:53am

    salvomil

    17 posts

    Hi Ajaxboy,

    and sorry if I repeat the question but I need to do a synchro call using the framework. How can I do it without using pure ajax or Jquery but using only Cjax?

    Thank you.

  • #175 / Jul 30, 2013 2:37pm

    fran-quero

    19 posts

    Is it possible to bind elements generated dinamically, like jQuery .live() or .on() methods?

    I have created an cAjax exec call to an element, that works when the element is in the main view, but doesn’t when it’s loaded by other cAjax call.

    $ajax->Exec('zip', $ajax->call(base_url().'ajax/newcustomer/locations/|zip|','location'), 'blur');
  • #176 / Aug 05, 2013 9:35am

    Ajaxboy

    243 posts

    As long the element exist you should be able to attach any event. Otherwise you might need to wait for some sort of trigger until the element is created.

  • #177 / Aug 05, 2013 10:17am

    Ajaxboy

    243 posts

    By the way, are you using firebug? or chrome ajax debugger? One of these is essential to be able to debug raw requests which give you more direct information while debugging and fixing stuff

  • #178 / Aug 11, 2013 6:16pm

    Needle

    12 posts

    Am I missing something simple here?

    I’ve installed AJAXFW CI 5.4, on Codeigniter version 2.1.4. When I go to run the initial test following the instructions on this page, I get a blank page with no message or error. The network inspector shows that ajax.php?test/test is being fetched successfully.

    I’ve tried this setup on both my local Codeigniter install as well as on a live remote server, both times with the same result. Any help getting this up and running would be greatly appreciated!

  • #179 / Aug 11, 2013 10:36pm

    Ajaxboy

    243 posts

    Make sure you meet the minimum requirements:

    https://github.com/ajaxboy/cjax

    Ps, the latest is Cjax 5.5

  • #180 / Aug 11, 2013 11:20pm

    Needle

    12 posts

    Hey, thanks for the speedy reply!

    I’ve upgraded to 5.5, but still no luck with the initial test. Just an empty page. I’m running locally on MAMP using a virtual host, so the URL looks like: dev.myproject:8888/ajax.php?test/test

    MAMP is running PHP 5.3.6

    I’m using MOD Rewrite to remove the index.php segment but I haven’t implemented the ajax rewrite rule that came with the project folder.

    My directory structure looks like this:

    application/
      - response/
          -sample.php
          -test.php
      - controllers/
          - AjaxController.php
      - views/
          test.php
          test2.php
    ajax.php
    ajaxfw.php
    cjax/
    examples/
    index.php
    system/

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

ExpressionEngine News!

#eecms, #events, #releases