Submit form and get echo from php in jquery -
i have form , submit button sends input values per post php file. php validates , echos value. how can handle echo value per jquery (in jquery function)?
sample code:
        <form id="login" method="post" action="/php/login.php">             <input type="text" id="username" name="username" placeholder="username" autofocus="true"></input>             <input type="password" id="password" name="password" placeholder="password"></input>             <button id="loginbutton" type="submit" name="submit">login</button>         </form>   just pretend /php/login.php is
<?php     echo "ok"; ?>   now, imagine there must way echo value in sort of form-submit callback in jquery?
ok, found out had elude actual submit , seperate post
$("#login").submit(function(event) {     event.preventdefault();     var myusername = …      var mypassword = …      $.post("/php/login.php", { username:myusername, password:mypassword }, function(data){          alert(data); // php echo.     });  });      
Comments
Post a Comment