Skip to content

Instantly share code, notes, and snippets.

@ojgarciab
Last active May 12, 2017 13:01
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 ojgarciab/f1ecb3c8e0b8291f2be640a7da69138b to your computer and use it in GitHub Desktop.
Save ojgarciab/f1ecb3c8e0b8291f2be640a7da69138b to your computer and use it in GitHub Desktop.
<script src="https://code.jquery.com/jquery-3.2.1.min.js"></script>
<script>
$(document).ready(function() {
$("body").on("submit", "form", function(event) {
event.stopPropagation();
event.preventDefault();
var type = "post";
var url = $(this).prop("action");
var cache = false;
var contentType = 'application/x-www-form-urlencoded';
var processData = true;
if (this['files[]'].files.length) {
var data = new FormData(this);
contentType = false;
processData = false;
} else {
var data = $(this).serialize();
}
$.ajax({
url: url,
data: data,
type: type,
contentType: contentType,
processData: processData
}).done(function(data) {
$(".section").html(data);
});
});
});
</script>
<form id="form" action="formulario.php" method="post">
<input type="text" placeholder="Pon algo..." name="campo" /><br />
<input type="file" name="files[]" multiple /><br />
<input type="submit" value="Enviar formulario" />
</form>
<pre class="section"></pre>
<?php
var_dump($_POST);
var_dump($_FILES);
var_dump(file_get_contents('php://stdin'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment