0

I have a few web-pages which have content loaded from a database (kind of a news website). And I have a page which provides an interface for adding articles, and modifying some of the web page elements, like header content or footer content of the site.

To save the information on the server I use this code (example):

// on button click (not form with type="submit") a function is called which retrieves HTML form values separately and sends them to the function below

function sendRequest(HEADER, FOOTER) {
    let xhttp = new XMLHttpRequest();
    xhttp.open("GET", `/server.js?header=${HEADER}&footer=${FOOTER}`);
    xhttp.send();
}

Where HEADER and FOOTER are some strings. The problem is that all spaces " " and any cyrillic characters also get encoded in hecadecimal like "%20" and "%D0%BA" (this one is an example, idk which character it corresponds to). Therefore, the text saved in the database, and retrieved from the database looks like a mess, and my browser (Google Chrome, latest version I believe) does not decode these hexadecimal values into normal text.

Is there a workaround to prevent character encoding, some way to easily decode the values into characters, or is it possible to fix this within the browser/system?


I'm still learning the basics, and my knowledge of back-end is terrible, therefore the design choices mentioned above were made because "they work good enough".

Alex F
  • 394
  • 1
  • 12

1 Answers1

0

This was a problem of using "GET" method. With "POST" I managed to send data correctly without encoding it:

function sendRequest(HEADER, FOOTER) {
    let xhttp = new XMLHttpRequest();
    xhttp.open("POST", `server.js`);
    xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
    xhttp.send(`header=${HEADER}&footer=${FOOTER}`);
}
Alex F
  • 394
  • 1
  • 12