lundi 29 janvier 2018

Assign values to input texts from Jquery Ajax [duplicate]

This question already has an answer here:

Hi everybody good morning:

I have trouble when retrieving values from an Ajax request and I don't know why... I'm getting crazy with this since 2 days ago:

HTML

<input name="txtCOD_ANALISTA" type="text" id="txtCOD_ANALISTA" 
maxlength="4" size="6" />
<input name="txtNOMB_ANALISTA" type="text" id="txtNOMB_ANALISTA" 
maxlength="150" size="42" />
<input name="txtFECHA" type="text" id="txtFECHA"
maxlength="10" size="10"/>

so, I made it save data... yeeeehhhh!, but when I try to retrieve data I use this:

$.ajax({
url: "../Pagweb/modeltablacomunidades.asp?tipo=40&ccdd="+$('#cboDpto_id option:selected').val()+"&ccpp="+$('#cboProvincia_id option:selected').val()+"&ccdi="+$('#cboDistrito_id option:selected').val()+"&area="+$('#cboArea_id option:selected').val(),

      type: "POST",
      cache: false,
      async: true,
      dataType: "json",
      success: function (response) {
          var resdatarow = JSON.stringify(response)
          var datacollet = JSON.parse(resdatarow);

          console.log(resdatarow);
          console.log(datacollet);
          console.log(datacollet.FECHA);
          console.log(datacollet[2]);

          $('#txtCOD_ANALISTA').val(datacollet.COD_ANALISTA);          
          $('#txtNOMB_ANALISTA').val(datacollet.NOMB_ANALISTA);
          $('#txtFECHA').val(datacollet.FECHA);
      }
    });

Then, when I check in Chrome Console, I can see the JSON object returned:

{"data":[{"COD_ANALISTA":"157 ","NOMB_ANALISTA":"SOTO CCANCCE JUAN CARLOS","FECHA":"26/01/2018"}]}
{data: Array(1)}
data: Array(1)
0: {COD_ANALISTA: "157 ", NOMB_ANALISTA: "SOTO CCANCCE JUAN CARLOS", FECHA: "26/01/2018"}
length: 1__
proto__: Array(0)__
proto__: Object
undefined
undefined

But I can't see anything in my 3 inputs :( Why is that? Why? What am I doing wrong? and when I put: console.log(datacollet.FECHA); or any field, it shows me "UNDEFINED"




Aucun commentaire:

Enregistrer un commentaire