I am sending the following string "Search not found" when sending it without the ú it takes it perfectly, but when it goes with ú I get the following error:
Uncaught DOMException: Failed to execute 'atob' on 'Window': The string to be decoded is not correctly encoded.
The js code is the following:
w._getParameterByName = function (name) {
name = name.replace(/[\[]/, "\\[").replace(/[\]]/, "\\]");
var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"),
results = regex.exec(location.search);
return results === null ? "" : atob(decodeURIComponent(results[1].replace(/\+/g, " ")));
};
I appreciate your help
The problem is that as long
atob
as theybtoa
only accept characters that occupy 1 byte andú
it is a 16-bit utf8 character, that is, it occupies 2 bytes and generates the error.If you can encode correctly, but the problem is decoding, it's probably due to the way you're doing it, maybe just putting
atob
inside:The solution proposed by Mozilla Developer is to encode the string, in such a way that it can be ensured that all characters occupy only 1 byte:
Update:
If you are encoding in base64 from PHP the option can be quite simple:
Then with javascript you just use
atob()
to retrieve the original string: