AJAX problem with ESP8266

I'm using a NodeMCU to serve a webpage on which I have a button with which I would like to change a variable in my Arduino code. I can do this by adding this in my code:

server.on("/change", [](){
  Serial.println("Change requested");
  if (input_string != "A different text!") {
    input_string = "A different text!"; 
  }
  else {
    input_string = "Hello world!";
  }
  server.send(200, "text/plain", "Changing!");
});

I was hoping to be able jut to add a button to the HTML page that makes an Ajax call, as follows:

<button onclick="makeAjaxCall('change')">Change!</button>

but this gives me errors. I'm not sure if I'm missing something in order to be able to run the Ajax call, but it just doesn't work. What I can do is this:

<button onclick="window.location.href='/change'">Change?</button>

But of course, that redirects the whole page, which I don't want. I want the page to stay, not to refresh, or go anywhere else, just to pass data to the code.

Am I missing something in the code? Is there another way to do this?

but that causes the page to refresh,

Oops, forgot the script to define the ajax call. Sorry to waste everyone's time!

Skeptic:
Oops, forgot the script to define the ajax call. Sorry to waste everyone's time!

Ideally you should post how you solved this with a bit of demo code and mark it [SOLVED] in the title (by editing the title in your first post). That could come handy for others members