Handle link in SPA to load partial

<div id="page-wrapper">

</div>


$('a.handle-link').click(function (e) {
    e.preventDefault();

    var currentLink = $(this).attr('href');
    $.ajax({
        url: currentLink,
        async: true,
        beforeSend: function () {
            $("#page-wrapper").fadeOut("slow").empty();
        },
        success: function (data) {
            $('#page-wrapper').hide().html(data).fadeIn("slow");
        },
        error: function (request, status, error) {
            alert("Error-  Request: " + request + ", Status: " + status + ", Error: " + error);
        },
        complete: function () {
            // $('div.sidenav').unblock();
        }
    });
});

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s