On the main page index.php I have various information obtained through sessions, for example the id
user, among other data.
Now I have a form with a single field ( input
)
<form id="tck" method="POST" action="employee.php">
<input type="text" name="ticket" maxlength="10">
<button type="submit">ticket</button>
</form>
How can I send more data to the request ajax
without adding more fields to the form.
I need to be able to receive from the request ajax
the id
user (id_usuario)
<script type="text/javascript">
$(function() { //document.ready es obsoleto desde jQuery 3
$('.dismiss').click(function () {
$('.response').fadeOut(500);
});
$('#tck').on('submit', function(e) {
e.preventDefault();
var data = $(this).serialize();
var request = $.ajax({
url: $(this).prop("action"),
method: $(this).prop('method'),
data: data,
dataType: "html"
});
request.done(function(response) {
console.log(response);
$('.response').html(response);
$(".response").fadeIn(200);
window.setTimeout(function () {
$('.response').fadeOut(500);
}, 6000);
});
request.fail(function(jqXHR, textStatus) {
alert('Hubo un error: ' + textStatus);
});
});
});
</script>
To send more data through
AJAX
you can use the data formatJSON
in that case what you can do is modify the variabledata
:and in
PHP
order to receive the data it does it like this:this way you can add all the data you want and get them one by one in
PHP