为什么我的代码不需要过滤器空白输入?

时间:2019-01-24 04:09:00

标签: javascript php ajax html5 web

晚安,我有一个问题,即使在输入为空时也要在输入中进行提交,并且它们当然具有必需的属性,并且无论如何都要发送数据,我不知道为什么,并且被我的php接收代码,我使用的是Ajax,由于我是初学者,所以不知道这是否会影响操作。

我的代码HTML:

<form  action="client/insert_client.php" method="post" id="formulario_crear_usuario"   class="contact-form row" name="contact-form">
            <div class="form-group col-md-6">
              <input id="dni" type="text" name="dni" class="form-control" required placeholder="Identificación" />
            </div>
              <div class="form-group col-md-6">
                  <input id="name" type="text" name="rsocial" class="form-control" required placeholder="Razón social" />
              </div>
              <div class="form-group col-md-6">
                  <input id="email"  type="email" name="email" class="form-control" required placeholder="Email" />
              </div>
              <div class="form-group col-md-6">
                  <input id="telefono"  type="text" name="telefono" class="form-control" required placeholder="Teléfono" />
              </div>

              <div class="form-group col-md-12">
                  <input  id="direction" type="text" name="direction" class="form-control" required placeholder="Dirección." />
              </div>
              <div class="form-group col-md-12">
                  <input  id="contact" type="text" name="contact" class="form-control" required placeholder="Contacto." />
              </div>
              <div class="form-group col-md-6">
                  <input  id="vendedor" type="text" name="vendedor" class="form-control" required placeholder="Vendedor." />
              </div>
              <div class="form-group col-md-6">
                  <input id="linea_cred"  type="text" name="linea_cred" class="form-control" required placeholder="Linea de credito" />
              </div>
              <div class="form-group col-md-4"> Duración pago
                  <input id="dur_cre"  type="text" name="dur_cr" value="30" class="form-control" required placeholder="Duración de credito." />
              </div>
              <div class="form-group col-md-4"> Credito disponible
                  <input id="cred_disp"  type="text" name="cred_disp" class="form-control" required placeholder="Credito disponible." />
              </div>

              <div class="form-group col-md-4"> TDA-ASIGNADA:
                  <select id="tda_asig"  type="text" name="tda_asig" class="form-control" required placeholder="tda_asignada." />
                    <option value=1>1</option>
                    <option value=2>2</option>
                    <option value=3>3</option>
                    <option value=6>6</option>
                  </select>
              </div>
              <div class="form-group col-md-12">
          <input type="submit" id="agregar" style="width:240px; height:50px" class="btn btn-default btn-primary pull-right" value="enviar" />
              </div>
          </form>

我的代码js-ajax:

var agregarContacto = document.getElementById('agregar');
var formulario = document.getElementById('formulario_crear_usuario');

function crearUsuario() {
  var form_datos = new FormData(formulario);
  for([key, value] of form_datos.entries()) {
    console.log(key + ": " + value);
  }
  var xhr = new XMLHttpRequest();
  xhr.open('POST', action, true);
  xhr.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
  xhr.onreadystatechange = function() {
      if(xhr.readyState == 4 && xhr.status == 200) {
          var resultado = xhr.responseText;
          console.log(resultado);
          var json = JSON.parse(resultado);
          if(json.respuesta == true) {
              registroExitoso(json);
              construirTemplate(json);
              var totalActualizado = parseInt(totalRegistros.textContent) + 1;
              totalRegistros.innerHTML = totalActualizado;
          }
      }
  }
  xhr.send(form_datos);
}

0 个答案:

没有答案