Skip to content

Instantly share code, notes, and snippets.

@arbo-hacker
Created January 28, 2016 20:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save arbo-hacker/bb33b8d53a09562f94aa to your computer and use it in GitHub Desktop.
Save arbo-hacker/bb33b8d53a09562f94aa to your computer and use it in GitHub Desktop.
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