S
S
SpeakeazyYT12019-03-17 20:11:39
JavaScript
SpeakeazyYT1, 2019-03-17 20:11:39

Why is data not being passed to getJSON (JQuery) whose source is var_dump?

Good evening.
To begin with, I created a function where I get a list of records of 1C-Bitrix Highload blocks:

public static function getMakes()
    {
    $entity_data_class = GetEntityDataClass(4);
    $rsData = $entity_data_class::getList(array(
       'select' => array('ID', 'UF_NAME')
    ));

    while($el = $rsData->fetch()){
      var_dump($el);
    }
    }

The next step is to encode the $_GET['action'] request into json:
echo json_encode( Akb::getMakes());
In the public part, I created a script:
$.getJSON("api.php", {
            action: "getAkbMakes"
        })
        .done(function(data) {
            var options = '<option value="" selected></option>';
            $.each(data, function(i, item) {
                options += '<option value="' + item.ID + '">' + item.UF_NAME + '</option>';
                $('#make').html(options);
            });
      alert("Test");
        });

Which should receive data from JSON and set values ​​to . Unfortunately, there was such a problem - no data appears and data is simply empty. What could be wrong?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
SerJook, 2019-03-17
@SpeakeazyYT1

The call to var_dump should not be here. It messes up the output.
Most likely, the getMakes() function should return an array of data.

$arr = [];
while($el = $rsData->fetch()){
      $arr[] = $el;
}
return $arr;

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question