1. text

    Page Accessed By jQuery or Http?

    Here is a little code snippet I have been working with to integrate into the cms I am building with Codeigniter. It is used to determine if the controller is accessed by jQuery ( an ajax request ) or by a normal http request.

    /* Access()
     * returns http if requested by http request
     * returns ajax if requested by ajax request
    */
    function access()
    {
        if( isset( $_SERVER['HTTP_X_REQUESTED_WITH'] ) 
            && (
                'XMLHttpRequest' == $_SERVER['HTTP_X_REQUESTED_WITH'] 
                OR 'ActiveXObject' == $_SERVER['HTTP_X_REQUESTED_WITH']
            )
        )
        {
            // Request identified as ajax request
            return 'ajax';
        }
        else
        {
            // Requested through basic http request
            return 'http';
        }
    }

    Any suggestions and help would be greatly appreciated.>

    You can comment over at my blogĀ http://willayers.net/

About

My Name is Will Ayers aka cointilt and this is where I will be posting all of my small tips and findings that happen while I develope websites and web apps. I hope this will be a place to look back at for help when faced with a development issue.

I develop websites, co-own Motive Media and went to Full Sail University. I use html5 and php.

I love Codeigniter & jQuery

My Personal Blog

http://twitter.com/cointilt/

http://virb.com/cointilt/

http://readernaut.com/cointilt/

Search

People I follow