Because my alert (), does not get to run ?, it will be that there is error on onadyadystatechange

1

This has the functionality to give click to call this function goLostpass; but it does not show me the message ie it does not go into onreadystatechange. The alert is to look for the error

function goLostpass() {
      // window.alert('Se presiono ENTER');
      var connect, form, response, result, email;

      email = __('email_lostpass').value;

      if (email != '') {
          form = 'email=' + email;
          connect = window.XMLHttpRequest ? new XMLHttpRequest() : new ActiveXObject('Microsoft.XMLHTTP');

          connect.onreadystatechange = function(){
            alert("Estoy aqui");
            if (connect.readyState == 4 && connect.status == 200) {
              if (connect.responseText == 1) {
                result = '1==1';

                __('_AJAX_LOSTPASS_').innerHTML = result;
                location.reload();
              }else{
                result = '1=x1';
                __('_AJAX_LOSTPASS_').innerHTML = result;
              }
            }else if (connect.readyState != 4){
                result = '1==2';

              __('_AJAX_LOSTPASS_').innerHTML = result;

            }

          connect.open('POST','ajax.php?mode=lostpass',true);
          connect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
          connect.send(form);
        }

      }else {
        result = '1==3';

        __('_AJAX_LOSTPASS_').innerHTML = result;
      }
    }
    
asked by Gamez 20.04.2017 в 18:06
source

1 answer

4

You are enclosing open(...) , setRequestHeader(...) , send(...) within onreadystatechange and must be outside, after the bracket:

      connect.onreadystatechange = function(){
        alert("Estoy aqui");
        if (connect.readyState == 4 && connect.status == 200) {
          if (connect.responseText == 1) {
            result = '1==1';

            __('_AJAX_LOSTPASS_').innerHTML = result;
            location.reload();
          }else{
            result = '1=x1';
            __('_AJAX_LOSTPASS_').innerHTML = result;
          }
        }else if (connect.readyState != 4){
            result = '1==2';

          __('_AJAX_LOSTPASS_').innerHTML = result;

        }

    }
    connect.open('POST','ajax.php?mode=lostpass',true);
    connect.setRequestHeader('Content-Type','application/x-www-form-urlencoded');
    connect.send(form);
    
answered by 20.04.2017 / 18:30
source