-
-
Save ojgarciab/f1ecb3c8e0b8291f2be640a7da69138b to your computer and use it in GitHub Desktop.
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
<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> |
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 | |
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