N
N
Nikolai Chuprik2018-04-13 16:14:00
PHP
Nikolai Chuprik, 2018-04-13 16:14:00

How to deal with strange characters in ajax request response?

1 . Server response to the usual:

xhr.open ('POST', 'confirm.php' );
xhr.setRequestHeader ('Content-type', 'text/plain');		
xhr.send ( ... );


should in this case contain only the string "2057-6". But as you can see, there are some whitespace characters ahead:
5ad0ab1c82bed056412875.jpeg
The answer is sent by the confirm.php script. I specifically checked that no one and nothing in it outputs anything extra in echo. Checked for empty lines before and after <? ?>. If you look at the result of confirm.php in a separate browser, then nothing superfluous is also visible : Out of
5ad0ab2ce5070278892002.jpeg

desperation, I even wrote: echo chop( ... ); Didn't work (as expected).

2. Further more interesting. On the client, I decided to ditch whitespace characters (this should work):
vm.contractData.contractId = xhr.responseText.replace( /\S/, '' );


But the result is below in the first picture. '2' mysteriously disappeared, and whitespace characters are still there?! At the same time, /\W/ does not help either, except that '2' is not erased.

Satan. What is point 1, what is 2. Tell me the solution. (There is of course JSON in stock, but somehow stupid in this case from a cannon).

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question