Answer the question
In order to leave comments, you need to log in
Why do extra spaces appear in json received via ajax?
The essence of the question is this:
I can’t understand where the extra spaces come from, the php script draws this:
PHP:
<?php
mb_internal_encoding("UTF-8");
$post_id = $_POST["id"];
require ("db_config.php");
$connect = pg_connect("host=".DB_HOST." dbname=Yamap_base user=".DB_USER." password=".DB_PASS."");
$sql = "SELECT * FROM marker_place WHERE id=1";
$result = pg_fetch_assoc(pg_query($connect,$sql));
echo json_encode($result, JSON_UNESCAPED_UNICODE);
pg_close($connect);
$.ajax({
type: "POST",
url: "get_baloon.php",
dataType: "json",
data: marker_id_injson,
async: false,
success: function (data) {
console.log(data);
}
});
Answer the question
In order to leave comments, you need to log in
I suspect that the field type is not VARCHAR, but CHAR, which is padded with spaces.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question