jquery移动登录提交无法正常工作

时间:2014-02-06 11:24:14

标签: javascript jquery html jquery-mobile

我的jquery移动登录提交无法正常工作

我的jquery代码如下......这里是jsfiddle http://jsfiddle.net/dD6Dg/

$('#loginform').submit(function (e) {
     alert("loggg");
     e.preventDefault();
     $.ajax({
         type: "POST",
         url: '/class/login.php',
         data: $(this).serialize(),
         success: function (data) {
             if (data === 'Login') {
                 window.location = '/user-page.php';
             }
             else {
                 alert('Invalid Credentials');
             }
         }
     });
 });

1 个答案:

答案 0 :(得分:3)

使用click事件代替submit,因为代码中没有提交按钮。您正在使用a标记,因为您需要使用click事件而不是submit

$('#loginform').click(function(e) {
alert("loggg");
    e.preventDefault();
    $.ajax({
       type: "POST",
       url: '/class/login.php',
       data: $(this).serialize(),
       success: function(data)
       {
          if (data === 'Login') {
            window.location = '/user-page.php';
          }
          else {
            alert('Invalid Credentials');
          }
       }
   });
 });

Fiddle