M
M
mrSeller2018-02-22 11:22:00
Character encoding
mrSeller, 2018-02-22 11:22:00

Correct encoding of values ​​during ajax request - how to fix it?

All my adult life I had no problems with this, I always sent such ajax requests, but today the backend showed me what I was doing wrong.
5a8e7b68785f7145607313.png
The site has many filters, one of which is the search bar.
Changing any filter changes the address bar using History.pushState, adding/removing variables.
With an ajax request, I simply get the value of each variable from the address and send it as an object to the server.

Thus, the search string has the corresponding kind of URL encoding.
And then the backend tells me that there should be a normal string of Russian characters, because Laravel cannot find anything for such a request.
But in my practice, this is generally the first time that the server does not eat such a request.

Do I need to decode this string on my side or is the backend lazy?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
A
Ainur Valiev, 2018-02-22
@vaajnur

xhr.setRequestHeader('Content-Type', 'application/json; charset=utf-8');

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question