V
V
Vladimir Sergeevich2016-02-08 19:53:54
PHP
Vladimir Sergeevich, 2016-02-08 19:53:54

Why do extra spaces appear in json received via ajax?

The essence of the question is this:
f9ce22dfcfac43efbc1ac3639739430c.png

I can’t understand where the extra spaces come from, the php script draws this:
0ea1458d312045ba8f92f4cf03233de6.png
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);

JS:
$.ajax({
        type: "POST",
        url: "get_baloon.php",
        dataType: "json",
        data: marker_id_injson,
        async: false,
        success: function (data) {
            console.log(data);
        }
    });

The answer, as you understand, I get with Postgresql, everywhere the field type is VARCHAR, of course I can remove the extra space in the loop, but maybe there is a more beautiful option?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry Vashkevich, 2016-02-08
@VladimirZhid

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 question

Ask a Question

731 491 924 answers to any question