Problem with jQuery and Ajax?

0

I have been trying to get the response from the server using a function between jQuery and Ajax, but as much as I send the information from the form I have no response from my request. I do not know what happens, because Ajax does not give me any kind of response.

Here part of the HTML code.

        <div class="container">

          <section class="row">
            <div class="col-md-6 offset-md-3">
              <h2 class="tituloLogin">Iniciar Sesión</h2>
              <form id="login">
                <div class="inputRojo input-group mb-3 mr-sm-2">
                  <div class="input-group-addon"><i class="fa fa-envelope-o" aria-hidden="true"></i></div>
                  <input type="text" id="email" class="form-control" placeholder="E-mail">
                </div>

                <div class="inputRojo input-group mb-2 mr-sm-2">
                  <div class="input-group-addon"><i class="fa fa-key" aria-hidden="true"></i></div>
                  <input type="password" id="passwd" class="form-control" placeholder="Contraseña">
                </div>
                <a href="#" class="btnContrasenaLogin mb-3">¿Olvidaste tu contraseña?</a>
                <button onclick="login()" class="btn btn-primary btn-block">Ingresar</button>        
                </form>
                <button type="button" class="btn btn-secondary btn-block mb-4"><i class="fa fa-facebook" aria-hidden="true"></i> Ingresar con Facebook</button>

                <a href="#" class="btnRegistrarme mb-3">Registrarme</a>

              </form>

            </div>
          </section>

        </div>

And here is my function, which is contained in a Javascript file.

    function login() {

        var em = $('#email').val();
        var pa = $('#passwd').val();

        alert(em);
        alert(pa);

        var url = 'http://www.kupomcity.com/gamma/api_v2.php?_opt=user&_act=login';

        var data = {
        email: 'em',
        passwd: 'pa'
        };  

      $.getJSON(url, function (data) {
        console.log(data);
        alert(data);    
      });    
      }  
    
asked by Nelson Jara Torres 31.07.2017 в 22:52
source

1 answer

0

When you create the variable data you assign the text em and pa to the keys email and passwd respectively, and not the value of the variables em and pa , remove the quotes maybe that's why it does not work for you.

    
answered by 31.07.2017 / 23:19
source