I trying to setup my forms to submit via AJAX so that I can display success/error messages in the page. My current submit function is below. The submission process is working fine, but I'm getting back a 'text' response with the entire HTML of the page. Based on the responses on this thread I was expecting JSON. I've tried setting xhr.responseType = "json"; which causes a null response. Is there a way to force the response to be JSON?

function ajaxFormSubmit(e) {
    let form = e.target
    let data = new FormData(form)
    let xhr = new XMLHttpRequest()
    // xhr.responseType = "json";
    xhr.open(form.method, form.action);
    xhr.onload = function() {
        if (xhr.readyState === xhr.DONE) {
            if (xhr.status === 200) {