• 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Ajax in CI

#1
Dear all,
i started 2 years ago writting with CI (i write code in php for > 25Years). I loved the power of Smarty - xajax/Jaxon - Swift. I managed to integrate all of them into CI (plus the hiding of /applications;/core; and so on).
Last year i try to update the part of Jaxon-php, but i have no success. Until the version of 2.0-beta28 works, but now newer one.
Now i try it again and i strucle on the same problem (never mind here). The developer from jaxon-php (better for jaxon-php/codeigniter) give no response over a year....

So i looked for a alternate for writing AJAX-Application in CI and wonder if all recommendations goes into native JQuery-Ajax-Calls. For a simple Ajax-Call in JQuery i need to wrote 16 Lines of Code in the template (i got it from a example Smile ).
To be honest: i like to write PHP-Code, but not more JQuery-Code as needed Angel

My lines of codes shows like this:

PHP Code:
// Initialize of Controller where a AJAX-Call is done after the template is rendered (onload)
// Jaxon.App is the automated genereated JS-Function-Namespace
// auswertungen_austria_ajax is the php-file where the Response-Class is in
// hole_liste(true) is a public method in the Response-Class (hole_liste = get_list in german)
 
public function Austritt() {
        $this->jaxon->register();
        $this->smarty->assign("seek_opt",array());
        $this->smarty->assign("zus_BodyOnl","Jaxon.App.auswertungen_austritt_ajax.hole_liste(true);");
        
        $this->smarty->view('benutzer-listenAustritt2-index.tpl', array(
            'jaxonCss' => $this->jaxon->css(),
            'jaxonJs' => $this->jaxon->js(),
            'jaxonScript' => $this->jaxon->script(),
        ));

PHP Code:
// Method of a response class to answer a request...
// with the response i can assign into elements whatever it needs - independent which template is used
// and i can call other functions in the class over javascript (from the client site)
// Jaxon.App = the generated functions from Jaxon
// auswertungen_ajax = the Class file for the Response
// refresh_table() = the public method that is called

public function icon_set($id) {
    
$temp $this->ci->da_workstep_model->get($id);
    
$content $this->ci->smarty->fetch("anw_detail_approved.tpl",["i" => $temp,"id" => $id]);

    
$this->response->assign("icon_workstep_approved_".$id,"innerHTML",$content);
        $this->response->script("Jaxon.App.auswertungen_ajax.refresh_table();");

PHP Code:
// Smarty-Template to send a response to the server side from a single "onchange" ...
// domains_ajax is the Class-File for Jaxon-Response
// rech_pos_add is the public method in the class
{strip}
<
select name=domain id=domain onchange="Jaxon.App.domains_ajax.rech_pos_add(this.value);">
    <
option value=0>{LP_say('-- Bitte auswählen--')}</option>
    {
html_options options=$arr_domain_liste selected=$dom_id}
</
select>
{/
strip

The example above has no interaction between, but should explain what i mean.
I have all changes of data in the place where it should be and have not struggle with different template-files (where the JQuery-Code for a AJAX-Request has to be, as i understand).
In my usage, i have only to know what the name of the field (element-ID) is, where i like to place data into.... (of course - most of the time i give the response-method the name as parameter where i like to insert the requested data Rolleyes )

So - my question is:
Is there a convenient AJAX-Library that gives the focus back to writing PHP-Code without the need the usage/learning of JQuery/Javascript ?
I searched the last weeks around, but had no real success. The last promising result i found is from Mr. ajaxboy (its called cjax), but his library is slited in Version 5.9 over to 2 years...

Could someone give me a glue ?
Help for upgrading jaxcon-core to the current 2.2.6 is also welcome Smile (it´s a real cool tool, but 2 year old code is a loose cannon Dodgy )
kr Tom
Reply

#2
You don't need to use an external library, it's built in into CI 3 and 4.
Here are an example on CI 3 I helped a user with earlier.
https://forum.codeigniter.com/thread-703...#pid352422

If you want to do it with plain JavaScript:
https://forum.codeigniter.com/thread-718...light=ajax
Reply


Digg   Delicious   Reddit   Facebook   Twitter   StumbleUpon  


  Theme © 2014 iAndrew  
Powered By MyBB, © 2002-2019 MyBB Group.