简体   繁体   中英

Every input is serializing on form submit PHP

Whenever I press the submit button on my form it just serializes in the url, the thing here is that I dont have any script/function included to make this happens.

I've another register form that uses ajax but this one is fine, the serialize works as it should.

my script:

$("#frmCadastro").submit( function() {

    dataString = $("#frmCadastro").serialize();

    $.ajax({
        type: "POST",
        url: "cadastroUsuario.php",
        data : dataString,
        dataType: "html",
        success: function(retorno) {
            $("#resposta").html(retorno);
        }

    });
    return false;
});

Just to mention, I've got 1 registration form that works well and another that I'm programming and this one is giving me headaches. I didn't even include the script and whenever I press submit all the inputs just serialize in the url, but if I put a destination on the action of the form when I press submit the destination is executed.

I think that's it, if you guys want more details just ask.

Adding this as an answer: If your form tag has the method="GET" it will serialize everything. Setting it to method="POST" should stop that, if you haven't tried it. Also, if you want to prevent the form from submitting itself (to let the ajax run first) just put in a return false; statement inside the function. Then after the AJAX runs, if you want, you can submit the form again with a $('formname').submit(); just like you have already.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM