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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -