jQuery ajax POST, error ‘SyntaxError: Unexpected end of JSON input’

Im sure im missing something simple, but so far struggling to see what…

I am wanting to POST some form field entries to a server in JSON format.
I am currently using:

$(document).ready(function () {
    $("#newEnquiery").submit(function (event) {     
        event.preventDefault(); 
        $.ajax({
            url: 'SERVER-URL-HERE',
            type: 'POST',
            data: JSON.stringify({ "name": $('#name').val(), "emailAddress" : $('#emailAddress').val(), "address" : $('#address').val() }),
            contentType: 'application/json; charset=utf-8',
            dataType: 'json',
            success: function(data, textStatus, jQxhr){
                console.log('Sent');
            },
            error: function( jqXhr, textStatus, errorThrown ){
                console.log('fail');
                console.log(errorThrown);
            }
        });
    });
});

The error that I am being shows in the console is; SyntaxError: Unexpected end of JSON input

Read more here: Source link