0
Man script works perfectly, but there are hours that requires the page of the registration sent a selection type category, and it sends to the address bar as if it were $_get
, but it’s all coming true $_post
in the serialize of jQuery.
How the error appears, being that it is via post: https://www.meusite.com.br/cadastro?pro=produto
How it’s supposed to be: https://www.sistema.g4w.com.br/cadastro
Javascript code:
// JavaScript Document
$(document).ready(function () {
//sessão de form produtos
$(function () {
$('#formss').on('submit', function (e) {
e.preventDefault();
$.ajax({
type: 'post',
url: 'matriz/mostra_select.php',
data: $('#formss').serialize(),
success: function (retorno) {
$('#prods').html(retorno);
}
});
});
});
});
HTML + PHP:
<form id="formss">
<select class="select" name="bd" style="width: 95%">
<option value=''>Selecione a Categoria para Cadastro dos Produtos</option>
</select>
<option value="categoria">categoria</option>';
<input type="submit" id="novo" />
</form>
<!-- no select vai uma busca em php, ele busca no arquivo em questão na ulr no js, e retorna pra mim,
porem tem horas que ele mostra como se tivesse ido via get
codigo php abaixo, o arquivo que recebe-->
<div class="main_produtos">
<?php
include('conecta.php');
$fila = $_POST['bd'];
$pega = $fila.'_lista';
$mostrando = "SELECT * FROM $fila order by cod desc limit 1";
$mm = mysqli_query ($con, $mostrando) or die(mysql_error());
$venda = mysqli_fetch_array($mm);
$cods = $venda['cod'];
if(empty($cods)){
$cods = '1';
?>
<?php
}
else{
$cods = $venda['cod'] + 1;
}
?>
Without seeing the code becomes difficult to give an accurate answer.
– Sam
And this
option
outside theselect
?– Valdeir Psr
was an editing error right here.. rs, the script is correct
– Evandro Aguiar
friend, the property that defines whether it is POST in $.ajax is not the method? Try to exchange the type for method
– Ademilson Santana da Silva
@Ademilsonsantanadasilva is not, I switched and sporadically continues the error
– Evandro Aguiar
Try setting method="post" in your html form tag. Now understanding better, is the address that it is firing the url different from the address it should be? Because the reference will be the URL that is at the time you send, so it varies from the address you are accessing.
– Juarez Turrini
@Juarezturrini I do not want him to direct to another page, but give me an answer in the same, even if it is another page
– Evandro Aguiar
"but there are hours"... strange this. In the programming area this statement does not match. Either it is or it is not. Your tb code has many inconsistencies. Could you at least edit the question and put exactly the correct code.
– Sam
the code is correct, I say "has hours" because he makes the request quiet, however he gives this bug that I can not solve
– Evandro Aguiar
Puts method="post" in <form tag>
– Kayo Bruno
Taken that in no part of the code there is the parameter
pro
nor the valueproduto
– user60252
As has been said, there are many inconsistencies in the code you have placed, from labels out of place,
'
which are over, etc ... so I suggest you put the code here in the question exactly like the one you have otherwise you won’t get the help you’re looking for. It is difficult to help when the code we see is all hypothetical and does not play with what you have that is "correct"– Isac
It is true @Isac, it is not enough the problem itself, add to it the sloppiness when posting the code correctly.
– user60252
Friend, it is not possible to reproduce the problem with the information you posted, so I will give two kicks. First of all, put in the ajax ' method: "POST" ', as it is in the official jQuery documentation. http://api.jquery.com/jquery.ajax/. So the kicks: first, in your html, there is no "action" in the form, which by default is get. So if your javascipt fails, for an untreated error for example, e.preventDefault() will never be triggered, and the upload will be in html form. When it fails, check your console for an error message. Second kick, your js script is not caching?
– Paulo Sakamoto
If you are caching, concatenate something in the file name. Example: <script src="app.js? v=2"></script>
– Paulo Sakamoto
@Paulosakamoto puts the answer that I will be positive, he did not give the answer json, but the get is gone from the bar
– Evandro Aguiar