Código:
index2.html
Código Javascript:
Ver original
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <link rel="stylesheet" type="text/css" href="css/bootstrap.css"> <title>jQuery Request AJAX</title> </head> <body> <section class="container"> <div class="page-header"> <h1>jQuery Request AJAX <small>Marc Garcia</small> </h1> </div> <article> <form> <label for="username">Nombre:<input type="text" name="username" id="username" class="form-control"></label> <label for="password">Pass:<input type="password" name="password" id="password" class="form-control"></label> <input type="button" name="submit" id="submit" class="btn btn-primary" value="Enviar"> </form> <div id="resultado"></div> </article> </section> </body> <script src="//ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script> <script src="js/bootstrap.min.js"></script> <script> $("submit").click(function () { var sendu = $("#username").val(); var sendp = $("#password").val(); $.ajax({ type: "POST", url: "request.php", data: "username="+sendu+"&password="+sendp, dataType: "json", success: function(msg, string, jqXHR) { alert(msg); } }); }); </script> </html>
request.php
Código PHP:
<?php
$nombre = $_REQUEST['username'];
$password = $_REQUEST['password'];
$list = array('nombre'=>$nombre, 'password'=>$password);
$c = json_encode($list);
echo $c;
?>