What does callback.call mean in jQuery?

Asked

Viewed 70 times

0

I’ve searched everywhere but can’t find an exact definition.

Follow my function and the snippet of my HTML where Dropdownlist is created:

function carregaSubCategoria(valor) {
  $.ajax({
    url: '/parceiros/subcategoria/lists-subcat',
    type: 'get',
    data: {
      id: valor
    },
    dataType: 'JSON',

    success: function(data) {
      var $teste = $('#subcategoria');

      $teste.empty();
      $teste.append($("<option></option>").attr("value", '').text('Selecione'));
      $teste.each(data, function(value, key) {
        $teste.append($("<option></option>").attr("value", value).text(key));
      });
    },
    error: function(data) {
      alert("oi errado");
    },
  });
}
<div id="div_categoria">
    <label class="label-control">Categoria</label>
    <select name="ofe_cat_id" id="ofe_cat_id" class="form-control" onchange="carregaSubCategoria($(this).val())">
        <option value="">Selecione</option>
        <?php foreach ($categorias as $categoria) {
            echo "<option value='".$categoria->cat_id."'>".$categoria->cat_nome."</option>";
        } ?>
    </select>
</div>

<div id="div_subcategoria">
    <label class="label-control">Subcategoria</label>
    <select name="subcategoria" id="subcategoria" class="form-control">
        <option value="">Selecione</option>
        <?php foreach ($subcategorias as $subcategoria) {
            echo "<option value='".$subcategoria->sub_id."'>".$subcategoria->sub_nome."</option>";
        } ?>
    </select>
</div>

Follow a part of the JSON file:

[  
   {  
      "sub_id":2,
      "sub_cat_id":3,
      "sub_cod":"00020002",
      "sub_nome":"Terror",
      "sub_desc":"Filmes de Terror"
   },
   {  
      "sub_id":3,
      "sub_cat_id":3,
      "sub_cod":"00030003",
      "sub_nome":"Aventura",
      "sub_desc":"Filmes de Aventura"
   }
]

I’m trying to run this code, but it keeps bringing me the error:

Typeerror: callback.call is not a Function

  • You can post a snippet of your JSON file and a snippet of your HTML that contains your tag with id "subcategory"?

  • Ready, added.

  • And an excerpt from the JSON file?

  • Where you’re being called call? Probably refers to Function.prototype.call which is a native javascript function and is available in all functions

  • The call is from a Jquery I took, from a ready-made layout, to activate some classes of boostrap.

  • JSON added also

  • So add this jQuery that got, after all the origin of the problem is in it

  • For now I commented on jQuery’s call from the entire site (the file has more than 10,000 lines of code), the problem has stopped, and the Dropdownlists are working, but in return, some layout features have been undone. I’m new in the area and I don’t understand much, but I think it’s easier I set up a layout and a jQuery of my own than trying to set up this whole file, no??

  • tries like this: $teste.each(Function(value, key) { $teste.append($("<option></option>"). attr("value", value). text(key); });

Show 4 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.