Do not update me Ajax Json

0

in the select that shows a list from an api in json

 <select id="Select"></select>

He goes to the js

function getData(){
  $.ajax({
    type: "GET",
    url: 'http://localhost:8000/api/api', 
    dataType: "json",
    success: function(data){
      $.each(data,function(key, registro) {
        $("#Select").append('<option value='+registro.id+'>'+registro.primer_nombre+'</option>');
      });        
    },
    error: function(data) {
      alert('error');
    }

  });
}

He shows me the values without problem but does not update automatically and does not show the last one created.

Additionally, I choose that value and sent it through post .

    
asked by Jhon Bernal 17.07.2018 в 21:54
source

1 answer

0

Seeing your code, I do not see anything strange, unless the data does not arrive. from here I have no way of checking that. On the other hand what makes me weird is the way you build the select field.

For my part I generate it in this way and replacing it in your code would be something like that, you could try and tell me.

function getData(){
  $.ajax({
    type: "GET",
    url: 'http://localhost:8000/api/api', 
    dataType: "json",
    success: function(data){
      $.each(data,function(key, registro) {
        $('#Select').append($('<option>', { 
          value: registro.id,
          text : registro.primer_nombre 
         }));
    },
    error: function(data) {
      alert('error');
    }
  });

}

    
answered by 17.07.2018 в 22:23