Remote jquery validation pass optional parameter?

My internal check only accepts 1 parameter: email

When I look at Firebug, I see that the request URL sends 2 parameters:

https://example.com/rest/checkDupEmail?newEmail=myEmail%40myEmail.com&email=

Here is the verification code ...

HTML

<input type="textbox" name="newEmail" id="newEmail"/>

Js

validator = $('#emailForm').validate({
    rules: {
        newEmail: {
            required: true,
            remote: {
                url: '/rest/checkDupEmail',
                data: { email: $('#newEmail').val()},
                dataFilter: function(data) {
                    var json = JSON.parse(data);
                    console.log($('#newEmail').val());
                    console.log(data);
                }
            }
        }
    }
});

As if he takes the HTML field that I specify (newEmail) and send it as a parameter?

+4
source share
2 answers

Quote OP :

"Like it takes an HTML field that I specify (newEmail) and send it as a parameter?"

Yes of course. This is the default behavior of the method remote... it sends data from the evaluated field.


It sends two data parameters due to how you configured it.

  • newEmail, , remote. remote.

  • , email, data.

    data: { email: $('#newEmail').val() },
    

, data , . newEmail - .

data newEmail . JavaScript jQuery Validate newEmail , .

data , email , newEmail... do not .

: http://jqueryvalidation.org/remote-method/

+3

, 2, .

data: { email: $('#newEmail').val() },

data: { email: function() { return $('#newEmail').val(); } },
0

Source: https://habr.com/ru/post/1568401/


All Articles