Animation effect before ajax call
<p>I've watched several tutorials on how to load content without having to refresh the browser. I'm also using history pushState and popstate to update the url dynamically depending on what site that is displaying. However even if this code works, I would like to be able to <code>make som page transition animation effects</code> > <code>call the Ajax function</code> > <code>then make some fadeIn animation effects</code>. So far i've had no luck in trying to do so. I tried to read up on Ajax (beforeSend: function(){}), but the success function seems to execute before the (beforeSend) function. Is there anyone that could point me in the right direction, or tell me what i possibly am doing wrong? I'd appriciate it!</p>

<pre><code>   $(document).ready(function() {

        var content, fetchAndInsert;

        content = $('div#content');

        // Fetches and inserts content into the container
        fetchAndInsert = function(href) {
            $.ajax({
                url: 'http://localhost:8000/phpexample/content/' + href.split('/').pop(),
                method: 'GET',
                cache: false,
                success: function(data) {
                    content.html(data);
                }
            });
        };

        // User goes back/forward
        $(window).on('popstate', function() {
            fetchAndInsert(location.pathname);
        }); 

        $('.buttonlink').click(function(){
            var href =  $(this).attr('href');

            // Manipulate history
            history.pushState(null, null, href);

            // Fetch and insert content
            fetchAndInsert(href);

            return false;
        });
});
</code></pre>

<p>Questions? Just ask!</p>

<p>Thanks beforehand!</p>

<p>/// E !</p>