Welcome Guest, Not a member yet? Register   Sign In
CI using Prototype
#1

[eluser]Rey Philip Regis[/eluser]
Hey guys, I need an advice with reagrds to writing ajax using Code Igniter. I made some simple sample code using CI and Prototype and its running. What I want to know now, is if Im doing it the right way, I mean if what Ive done (the coding style) is correct. Please give me some advice on this.

Steps:

Step 1: Create an htaccess file and configure the config.php.

Step 2: Put the put the scriptaculous folder (with scriptaculous.js and prototype.js) in the system folder.

Strp 3: Code

Heres the code:

Code:
Controller: (ajax.php)

<?php
class Ajax extends Controller
{
    public function Ajax()
    {
        parent::Controller();
    }
    
    public function showMessage()
    {
        echo 'Good Morning everybody.';
    }
    
    public function index()
    {
        $this->load->helper('form');
        $this->load->helper('url');
        
        $data['title'] = 'Simple Ajax using Code Igniter & Prototype';
        
        $this->load->view('simple_ajax.php', $data);
    }
}
?>

Code:
View: (simple_ajax.php)

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
&lt;html &gt;
&lt;head&gt;
&lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt;
&lt;title&gt;&lt;?php echo $title; ?&gt;&lt;/title&gt;

function callAjax()
{
    var url = 'http://localhost/ci/ajax/showMessage';
    
    new Ajax.Request(
                        url,
                        {
                            method: 'GET',
                            onFailure: function()
                            {
                              $('display')[removed] = 'Failed'
                            },
                            onSuccess: function(transport)
                            {
                              $('display')[removed] = transport.responseText                            }
                        }
                     );
}


&lt;/head&gt;

&lt;body&gt;

    <div id="display">No Message</div>

    &lt;?php
        $data = array(
                        'name' => "button",
                        'id' => "button",
                        'type' => "button",
                        'content' => "Click",
                        'onClick' => "callAjax()"
                        );
                        
        echo form_button($data);
    ?&gt;
    
&lt;/body&gt;
&lt;/html&gt;

Any advice to improve?

By the way that's not [removed] that's innerHTML. Why does that change?

Good day.....


Messages In This Thread
CI using Prototype - by El Forum - 11-03-2008, 12:03 PM
CI using Prototype - by El Forum - 11-03-2008, 12:11 PM
CI using Prototype - by El Forum - 11-03-2008, 02:52 PM
CI using Prototype - by El Forum - 11-03-2008, 03:05 PM
CI using Prototype - by El Forum - 12-19-2009, 10:14 PM
CI using Prototype - by El Forum - 12-20-2009, 10:53 PM



Theme © iAndrew 2016 - Forum software by © MyBB