Welcome Guest, Not a member yet? Register   Sign In
Does Code Igniter has build in Ajax Support
#8

[eluser]Lukifer[/eluser]
I rolled my own AJAX helper, using Prototype rather than jQuery (both are quite good, I just have more experience with the former). Here it is, in case you find it helpful:

Code:
# AJAXANCHOR: Creates link which hits URL and replaces the contents of provided CSS id
# Usage: echo ajaxAnchor('css_id_to_update', 'http://url/here', 'Name of Link');
if(!function_exists('ajaxAnchor'))
{
    function ajaxAnchor($div, $url, $label, $more = '')
    {    return '<a href="#" onclick="new Ajax.Updater(\''.$div.
            '\', \''.$url.'\'); return false;" '.$more.'&gt;'.$label.'</a>';
    }
}

# TOGGLELINK: Creates link that shows/hides provided CSS id
# Usage: echo toggleLink('css_id_to_toggle', 'Name of Link');
if(!function_exists('toggleLink'))
{
    function toggleLink($div, $label, $more = '')
    {   return '&lt;a href="#" onclick="$(\''.
        $div.'\').toggleClassName(\'hidden\'); return false;" '.
        $more.'&gt;'.$label.'</a>';
    }
}

# AJAXFORM: Create simple form that posts with AJAX
# Usage: echo ajaxForm('css_id_to_update', 'http://url/to/post/to');
if(!function_exists('ajaxForm'))
{
    function ajaxForm($div, $url, $more = '')
    {    return '&lt;form action="'.$url.'" onsubmit="new Ajax.Updater(\''.
         $div.'\', this.action, {parameters:this.serialize(),evalScripts:true});'.
         'return false;" method="POST" '.$more.'&gt;';
    }
}

# AJAXLOAD: Immediately fires AJAX call, replacing content of CSS id
# Usage: echo ajaxLoad('css_id_to_load_in', 'http://url/here');
if(!function_exists('ajaxLoad'))
{
    function ajaxLoad($div, $url)
    {    return 'new Ajax.Updater(\''.$div.'\', \''.$url.'\');';
    }
}

EDIT: ajaxLoad string should be wrapped in script tags, the forum is eating them. Tongue

Looking forward to CI/EE 2.0's abstracted JS libraries! Smile


Messages In This Thread
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 05:35 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 05:52 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 06:02 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 06:35 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 06:36 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 06:49 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 07:15 AM
Does Code Igniter has build in Ajax Support - by El Forum - 06-02-2008, 10:06 AM



Theme © iAndrew 2016 - Forum software by © MyBB