Problem with Get in jquery

0

My script works perfectly, however it has hours that require the page of the file to be sent a selection type category, and it sends to the address bar as if it were $_get , however everything is via $_post in serialize of jQuery .

As the error appears, it is via post : link

How to be: link

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;
    }

?>
    
asked by anonymous 08.09.2018 / 22:00

1 answer

1

Friend,

First, change the ajax option, from "type: 'post'" to "method: 'POST'", as found in the jQuery $ .ajax :

$.ajax({
    method: 'POST',
    url: 'matriz/mostra_select.php',
    data: $('#formss').serialize(),
    success: function (retorno) {
        $('#prods').html(retorno);
    }
});

As for the error itself, it is not possible to reproduce it, but a probable reason is a javascript execution error, which may be interrupting the execution of the error, in which case e.preventDefault() will never be activated and the form will be sent by the html form (GET method by default). When you encounter the error, see browser console (in Chrome pressing F12) and see if you have any javascript errors.

Another possible reason is that on certain pages the script may be loading from the cache. In this case concatenate something in the filename. Example:

<script src="app.js?v=2"></script>
<form id="#formss" method="post"></form:

I hope it helps.

    
26.09.2018 / 23:02