click hijack head

HTTP HEAD request via AJAX?

by ryanttb

HTML

<a href="http://wordpress.org/news/2013/12/parker/">WordPress</a>
<a href="http://fjdkshfjdkshkjfdsfkdhsjk.com/">Nothing</a>

<h2>head tests</h2>

<div class="output">
</div>

CSS

a {
    display: block;
}

JavaScript

$(function( ) {

/* head tests */

$o = $('.output');
    
    /* base click handler */
$('a').click(function() {
    
    var defer = $.ajax( {
        url: $(this).prop('href'),
        type: 'HEAD',
        complete: function( xhr, textStatus ) {
            $o.html($o.html() + 'complete: ' + textStatus + '<br>');
        },
        error: function( xhr, textStatus, errorThrown ) {
            $o.html($o.html() + 'error: ' + textStatus + errorThrown + '<br>');
        },
        success: function( result, xhr ) {
            $o.html($o.html() + 'success: ' + 'ok' + '<br>');
        }
    } );
    
    return false;
});
    
});