php - Jquery Mobile - Getting an ajax result issue -


trying simple web app jquery mobile. have put simple log in form ajax results displayed. problem ajax not getting result when alert out see if url valid. there special need using jquery mobile?

any thoughts/answers appreciated!

here html code:

    <div data-role="page" id="login" data-theme="a" data-add-back-btn="true">         <div data-role="header">             <h2>log in</h2>         </div>             <div data-role="content" data-theme="a" data-add-back-btn="true">                    <form action="mobilelogin.php" method="post">                   email: <input type="text" name="email" id="useremail">                   password:  <input type="password" name="password" id="userpassword">                 <input type="submit" value="enter">                 </form>                 <div id="loginresult"></div>             </div>         <div data-role="footer"><h4>chris sherwood design 2012</h4></div>     </div> 

js file:

$(document).ready(function() {    $('form').submit(function() {   var emailchecker = /^([\w-\.]+@([\w-]+\.)+[\w-]{2,4})?$/;   var email = $("#useremail").val();   var userpassword = $("#userpassword").val();   var checklength = userpassword.length;    if(email == ""){     alert('please fill in email field');      return false;   }else if(userpassword == ""){     alert('please fill in password field');      return false;   }else if((!emailchecker.test(email))){     alert('please use valid email');      return false;     }else if(checklength < 6 || checklength > 6){     alert('password must 6 characters');      return false;    }else{   var datastring = $(this).serialize();   alert(datastring);   return false;         $.ajax({         type: "post",         url: "mobilelogin.php",         data: datastring,         success: function(data){         $("#loginresult").html(data);         }         });    }    }); 

php

<?php echo 'nothing special here...'; ?> 

from code:

return false;     $.ajax({     type: "post",     url: "mobilelogin.php",     data: datastring,     success: function(data){     $("#loginresult").html(data);     }     }); 

you returning false before ajax request.

edit (assumed simple mistake, have added more explanation)

you need either move return false; below ajax() call, or use event object so:

$('form').submit(function(e) {     e.preventdefault(); 

the problem using return false; if there error in before it not stop default action. if ajax request errors miss return false; , start loading action page.


Comments

Popular posts from this blog

delphi - How to convert bitmaps to video? -

jasper reports - Fixed header in Excel using JasperReports -

python - ('The SQL contains 0 parameter markers, but 50 parameters were supplied', 'HY000') or TypeError: 'tuple' object is not callable -