尝试将ajax获取请求发送到Go网络服务器,但响应给出500内部服务器错误

I'm trying to implement an ajax request that sends simple form data to a Go webserver, then return the same values in a response to the client (website).

Ajax request in javascript:

function addWheel(){
title = document.getElementById('title').value;
desc = document.getElementById('desc').value;

var xhttp = new XMLHttpRequest();
xhttp.onreadystatechange = function() {
    if (this.readyState == 4 && this.status == 200) {
        console.log(this.responseText);
    }
};
xhttp.open("GET", "/getCardInfo?title=" + title + "&desc=" + desc, true);
xhttp.send();

}

There error from the browser console I recieve says the internal server error occurs in "xhttp.send();"

Code from the webserver:

func ajaxHandler(w http.ResponseWriter, r *http.Request) {
//parse request to struct
fmt.Println("Ajaxhandler")
var d Data
err := json.NewDecoder(r.Body).Decode(&d)
q := r.URL.Query()
d.Title = q.Get("title")
d.Desc = q.Get("desc")
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
}

// create json response from struct
a, err := json.Marshal(d)
if err != nil {
    http.Error(w, err.Error(), http.StatusInternalServerError)
}
_, err = w.Write(a)
if err != nil {
    fmt.Println("handle error")
}

}

It runs all the way through without throwing any errors. It looks like it sends it at w.Write(a), so I assume there's an issue in my javascript. The variable d Data is just a struct containing 2 strings.

The handle function is defined in main like this: http.HandleFunc("/getCardInfo", ajaxHandler)

Can anyone see where the error lies?