Bablu Ahmed
Bablu Ahmed

Reputation: 5010

What is actually request type 'HEAD' in ajax?

In my code, I have got request type HEAD but I actually don't know details about it. The code is like this:

function fileExists(pUrl)
{
    let fileExist = false;

    $.ajax({
        url:pUrl,
        type:'HEAD',
        async:false,
        success: function()
        {
            //file exists
            fileExist = true;
        },
        error: function()
        {
            //file not exists
            fileExist = false;
        }
    });

    return fileExist;
}

Can anybody tell me about the HEAD? thanks in advance

Upvotes: 3

Views: 3247

Answers (1)

FZs
FZs

Reputation: 18619

The HEAD HTTP request type is similar to GET, but only returns the header part of the result.

In your code, it will get back the response's HTTP status code, but won't download the file itself.

See the docs at MDN

Upvotes: 6

Related Questions