2
Good morning.
I have the following code:
<form id="enviavenda" method="POST" action="" autocomplete="off">
<input class="input_codBarras" id="codBarras" name="codBarras" type="number" />
<input class="input_quantidade" id="on2Focus" name="quant" type="text" />
<input id="btn_cadVenda" type="submit" value="enviar" style="display: none;">
</form>
<script type="text/javascript">
$(function(){
var newcodBarras = $("#codBarras").val();
var newquantidade = $("#on2Focus").val();
var sdata = { codBarras : newcodBarras, quantidade : newquantidade }
$('#enviavenda').submit(function(){
$.ajax({
url: '../arquivos/php/caixaCadastraVenda.php',
type: 'POST',
data: sdata,
success: function(data){
$('.recebeDados').html(data);
}
});
$("#codBarras").val('');
return false;
});
});
</script>
Problem:
Fields that have been entered into jQuery variables are not being passed to the url page. It only works when I step
data: $("#codBarras").serialize(),
But I need to pass two input fields (or more).
In the box fileCadastraVenda.php , when I call $_POST['quantity'] or $_POST['codBarras'] it has an error that there is no such field.
How to pass more than one variable on the Ajax date?
The ajax is working or the page is being reloaded?
– fernandosavio
The page is not being reloaded according to the command of the script Return false, but the registration in the database does not happen because PHP informs that the file $_POST["quantity"] does not exist.
– Jéfferson Maurício
If the page is not being reloaded, in principle just put the 3 lines that start with
var ...
within Ubmit. you are picking up data that has not been filled in yet and you are using it in the form– fernandosavio