Problems When passing data via ajax

0

I have a form where it is validated by jqBootstrapValidation.js, and it is sent to another file, which is the file below:

// Contact Form Scripts

$(function() {

    $("#usuariosForm input,#usuariosForm textarea").jqBootstrapValidation({
        preventSubmit: true,
        submitError: function($form, event, errors) {
            // additional error messages or events
        },
        submitSuccess: function($form, event) {
            event.preventDefault(); // prevent default submit behaviour
            // get values from FORM
            var txtnome = $("input#txtnome").val();
            var ememail = $("input#ememail").val();
            var txtusuario = $("input#txtusuario").val();
            var pwdsenha = $("input#pwdsenha").val();
            var urltxt = $("input#urltxt").val();

            var firstName = name; // For Success/Failure Message
            // Check for white space in name for Success/Fail message
            if (firstName.indexOf(' ') >= 0) {
                firstName = name.split(' ').slice(0, -1).join(' ');
            }

            $('#submit').html("...Enviando");
            $('#submit').prop("disabled", true);

            $.ajax({
                url: urltxt,
                type: "POST",
                data: {
                    txtnome: txtnome,
                    ememail: ememail,
                    txtusuario: txtusuario,
                    pwdsenha: pwdsenha
                },
                cache: false,
                success: function() {
                    // Success message
                    $('#success').html("<div class='alert alert-success'>");
                    $('#success > .alert-success').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-success')
                        .append("<strong>Registro realizado com sucesso</strong>");
                    $('#success > .alert-success')
                        .append('</div>');

                    //clear all fields
                    $('#usuariosForm').trigger("reset");
                    $('#submit').html("Enviar mensagem");
                    $('#submit').prop("disabled", false);

                },
                error: function() {
                    // Fail message
                    $('#success').html("<div class='alert alert-danger'>");
                    $('#success > .alert-danger').html("<button type='button' class='close' data-dismiss='alert' aria-hidden='true'>&times;")
                        .append("</button>");
                    $('#success > .alert-danger').append($("<strong>").text("Desculpe " + firstName + ", ocorreu um erro. Por favor tente novamente!"));
                    $('#success > .alert-danger').append('</div>');
                    //clear all fields
                    $('#usuariosForm').trigger("reset");
                },
            });
        },
        filter: function() {
            return $(this).is(":visible");
        },
    });

    $("a[data-toggle=\"tab\"]").click(function(e) {
        e.preventDefault();
        $(this).tab("show");
    });
});


/*When clicking on Full hide fail/success boxes */
$('#name').focus(function() {
    $('#success').html('');
});

But I'm in trouble, as I have several forms I always wanted to use the same function. and pass the url to it to do the sql correctly, that is, if I go to the user registration page it will do user registration. if it passes update_user it goes to the user change page. I tried a method of passing the url to ajax as follows:

<input type="text" name="urltxt" id="urltxt" class="form-control text-center" value="?folder=usuarios/&file=ins_usuarios_usuarios&ext=php" data-validation-required-message="Por favor não mude os dados." required>

And in the file it would receive in a variable, but it is not working. How can I do this? thank you very much! NOTE: The nomenclature of my pages are:? Folder = users / & file = ins_user_users & ext = php

I debugged the code see:

    
asked by anonymous 08.05.2017 / 14:36

1 answer

1

Replace inp value:

<input type="text" name="urltxt" id="urltxt" class="form-control text-center" data-url="?folder=usuarios/&file=ins_usuarios_usuarios&ext=p‌​hp" data-validation-required-message="Por favor não mude os dados." required> 

And in Js get the new property:

var urltxt = $("input#urltxt").data("url");

In case of information security: If it is a user registry, you will pass the password that it has set and encrypt on the server, from there, ngm plus, besides the user, will know the password. (Of course this will depend on the encryption algorithm used). In the case of the user edition, it will already be encrypted, so it is quiet.

Encrypt in js: What's the use? If I can see your code js? (=

    
08.05.2017 / 16:35