ajax send variable undefined to app.js (using nodejs)

1

this is my code, to send the variable "copying", but only shows by undefined console

    var texto="no existe 1 rayo zapato zanahorea karaoke Whisky software wikipedia jinete japon jabon facil frio rayo yogur habil hablar galleta gigante gentil valiente vehiculo vegetariano quebrado quemado botella bandido brazil baile patata patria palabra marcial maqueta manantial caballero temperatura tercero ubicar urgente delfin delgado danza lectura laboratorio ilusivo inadvertencia ilimitado nacido narrado racionalidad radiactivo racismo satelite septiembre obstruir oscilatorio elogioso embajada emblema abundancia kiwi";
    var copiando;


        $(function () {
            var captureInput = $('.clickme');
            $(captureInput).focus();
                $(captureInput).keyup(function(event){

                    startUPDOWN= (new Date()).getTime();
                    if (!is_special_key(event.keyCode)) {
                        var delta= startUPDOWN - startPressUP;

                        copiando=delta;
                        key_cadaTecla.push(new claves(event.keyCode,tiempoPulsacion));

                        document.getElementById("keyCadaTecla").innerHTML = "tiempo de cada tecla:  ";
                        for (var i = 0; i < key_cadaTecla.length; i++) {
                                var result=document.createTextNode("("+key_cadaTecla[i].id+" "+key_cadaTecla[i].time+")");
                                document.getElementById("keyCadaTecla").appendChild(result);
                            };
                        document.getElementById("ult").innerHTML = "tiempo de Press a Up:   " + delta ;
                        teclaActual=event.keyCode;
                    };  
                    tiempoPulsacion=0;
                }); 
        });


$(window).on('load', function() {           

    var id = 'idUsuario';
    $('#add-new-fact').click(function() {
    var fact = $('#new-fact').val();
    $.ajax({
      type: "POST",
      url: "/servidor",
      data: { fact: copiando},
     // contentType: "application/json; charset=utf-8",
      dataType: "json",
      success: function(data) {
        alert("si");
        $('<li>').appendTo('#facts').text(fact);
        $('#new-fact').val('');
      },
      error: function(err) {
        var msg = 'Status: ' + err.status + ': ' + err.responseText;

        document.open("text/html", "replace");
        document.write(err.responseText);
        document.close();
      }
    });
    return false;
  });

        }); 
    
asked by hubman 17.09.2016 в 08:10
source

1 answer

1

If the variable has the value undefined it means that its value has never been updated since it was declared. Therefore, it follows that there is something wrong within keyup .

I recommend you to see the value of copiando in the course of the event.

    
answered by 17.09.2016 / 14:37
source