Created
January 28, 2016 20:14
-
-
Save arbo-hacker/bb33b8d53a09562f94aa to your computer and use it in GitHub Desktop.
Demostracion de serializeArray() de JQuery
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
if (isset($_POST['first_name'])){ | |
echo json_encode($_POST); | |
exit; | |
} | |
?> | |
<html> | |
<head> | |
<title>Test Serialize Array</title> | |
<script src="http://code.jquery.com/jquery-2.2.0.min.js"></script> | |
<script> | |
$(document).on('click', '#btnSubmit', function(){ | |
var forma = $('#data_form').serializeArray(); | |
$.post(window.location.pathname, forma, function(r){ | |
var res = $.parseJSON(r); | |
console.log(res.first_name); | |
}); | |
}); | |
</script> | |
</head> | |
<body> | |
<form id="data_form" method="post"> | |
<input type="text" id="first_name" name="first_name" placeholder="First Name"/> | |
<input type="text" id="last_name" name="last_name" placeholder="Last Name"/> | |
<textarea id="description" name="description" placeholder="Description"></textarea> | |
<input type="button" id="btnSubmit" value="Show Data"> | |
</form> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment