Welcome Guest, Not a member yet? Register   Sign In
Ajax Updater problem
#1

[eluser]Unknown[/eluser]
Hello,
i am new on CI and ajax but not in PHP.
To use CI it's ok and easy (very good framework).
I need some help to understand how use the ajax library.
I try to follow the tutorial of Derek Allard but the ajax updater function doesn't work.
The model list a table and output a form to allow updating and deleting for each result.
The controller by the index function put the output model in a variable and load a view
The view show the output in a div. The view include all the js files of ajax library and a js file with Ajax.Updater function.
In the controller a function update the modifies values submitted by the form in view page.
Without ajax all works fine.
But with ajax (like explain in the Derek Allard tutorial) the page is reload or only the form is showed in the view.
So i would like to undertand how use ajax.updater.
I'm sorry about my english. I do my best.
Thanks.
#2

[eluser]Référencement Google[/eluser]
Without some code it's difficult to help you, so please, post your code here.
#3

[eluser]Unknown[/eluser]
Ok so these is the controller with index and ajaxmodifier function

Code:
function index() {

        $data['title'] = "test ajax";
        $data['extraHeadContent'] = '';
        $data['search_results']=$this->test_ajax_model->resultats();
        $this->load->view('administration/index',$data);

    }


    function ajaxmodifier()

    {

        $libelle_vege = $this->input->post('libelle_vege');
        $frais_structure_vege = $this->input->post('frais_structure_vege');
        $marge_brut_vege = $this->input->post('marge_brut_vege');
        $id = $this->input->post('id');

        echo $this->test_ajax_model->modifier($libelle_vege,$marge_brut_vege, $frais_structure_vege, $id);

    }

the model
Code:
function resultats(){

        $query = $this->db->get('ref_prod_vegetale');

        $output = "&lt;form id='form_ajax' action='test_ajax/ajaxmodifier' method='post'&gt;<ul>";
        foreach($query->result() as $ligne){

            $output .="<li><b>&lt;input type='text' value='".$ligne-&gt;libelle_vege."' name='libelle_vege' id='libelle_vege'><br>";
            $output .= "&lt;input type='text' value='".$ligne-&gt;marge_brut_vege."' name='marge_brut_vege'>  &lt;input type='text' value='".$ligne-&gt;frais_structure_vege."' name='frais_structure_vege'>&lt;input type='submit' value='modifier' name='modifier'&gt;&lt;input type='hidden' name='id' value='".$ligne-&gt;id."'></li>";

        }
        
        $output .= "</ul>&lt;/form&gt;";
        return $output;
    }

    function modifier($libelle_vege,$marge_brut_vege, $frais_structure_vege, $id) {

        
        $info = array(
               'libelle_vege' => $libelle_vege,
               'marge_brut_vege' => $marge_brut_vege,
               'frais_structure_vege' => $frais_structure_vege);
        $this->db->where('id', $id);
        $this->db->update('ref_prod_vegetale', $info);
        $output = $this->resultats();
        return $output;
    }

the view
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">

&lt;html xmlns="http://www.w3.org/1999/xhtml"&gt;

&lt;head&gt;

&lt;meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /&gt;

&lt;title&gt;&lt;?= $title;?&gt;&lt;/title&gt;



//&lt;![CDATA[

base_url = '&lt;?= base_url();?&gt;index.php/';

//]]>









&lt;!-- the scriptaculous javascript library is available at http://script.aculo.us/ --&gt;

&lt;?php

if (isset($extraHeadContent)) {

    echo $extraHeadContent;

}

?&gt;

&lt;/head&gt;

&lt;html&gt;

&lt;body&gt;

    

    <div id='test'>test div ajax</div>

    <div id="resultats_2">

        &lt;?= $search_results;?&gt;

    </div>

&lt;/body&gt;

&lt;/html&gt;

the js function
Code:
window.onload = function () {

    

    $('form_ajax').onsubmit = function () {

        inline_results();

        return false;    

    }

}



function inline_results() {

    new Ajax.Updater ('resultats_2', base_url+'test_ajax/ajaxmodifier', {method:'post', parameters:Form.serialize(this)});
    new Effect.Appear ('resultats_2');


}

i'm sure i do something wrong but i can't find where
thanks fro your help.




Theme © iAndrew 2016 - Forum software by © MyBB