Create a gist now

Instantly share code, notes, and snippets.

What would you like to do?
Demostracion de serializeArray() de JQuery
<?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