Question

I need to ask a quick question and probably a dumb question since I'm new to JQuery anyway why isn't this script working? It looks fine but isn't doing anything do i need to call the functions in the HTML some how?

             <td>UserName</td>
            <input type="text" name="user_login" id="user_login">
        <br>
             <td>Password</td>
             <input type="password" name="user_pass" id="user_pass">
          <br>

             <td><input type="checkbox" name="remember_me" id="remember_me"> </td><td>Remember Me For 2 Days</td>

          </tr><br>
          <tr id="button_box">
             <td>&nbsp</td>
             <td><input type="button" name="submit" value="Sign In" class="button" onclick="check(e)"></td>
          </tr>
          <tr><td colspan="2" id="flash"></td></tr>

</div>

JS

$(document).ready(function () {
   // Make a function that returns the data, then call it whenever you
   // need the current values
   function getData() {
       return {
           user_login: $('#user_login').val(),
           pass_login: $('#user_pass').val()

       }
   }


   function loading(e) {
       $('#content').html('Loading Data');
   }

   function clearfields() {
       $('#user_login').val('');  //Clear the user login id field
       $('#pass_login').val('');  //Clear the user login password field        
   }

   function check(e) {
       e.preventDefault();
       $.ajax({

           url: 'ajax/check.php',
           type: 'post',
           error: function () {
               //If your response from the server is a statuscode error. do this!!!
               clearfields();
           },
           beforeSend: function () {
               $('#loading').fadeIn(800);
               //loading(e);
           },
           data: { user_login: $('#user_login').val(), pass_login: $('#pass_login').val() }, // get current values
           success: function (data) {
               //if your response is a plain text. (e.g incorrect username or password)

               if (data.indexOf("incorrect username or password") > -1) {
                   clearfields();
               }

               $('#loading').fadeOut();
               $('#content').hide();
               $('#content').fadeIn(1000).html(data);

           }

       });

   }

   // Don't repeat so much; use the same function for both handlers
   $('#field').keyup(function (e) {
       if (e.keyCode == 13) {
           var username = $('#user_login').val();
           check(e);

       }
   });

   $('#submit').click(function (e) {
       if (e.keyCode != 13) {
           check(e);
       }


   });

});

Pas de solution correcte

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top