Ayush Gupta Ayush Gupta - 2 months ago 7
jQuery Question

Send Parameter via POST Instead of GET in remote rule of JQuery Validation Library directly?

I am trying to learn

JQuery
, and was trying to understand the various rules in the
validate
library(https://jqueryvalidation.org/).
However, I noticed that even if my HTML
<form id="myform">
has
method="POST"
, the remote request to my check-email.php is sent via GET and not POST. Here is the
validate
rule I'm using:

$( "#myform" ).validate({
rules: {
email: {
required: true,
email: true,
remote: "check-email.php"
}
}
});


I am wondering how I can send the request to
check-email.php
via
POST
instead of
GET
without using any explicit AJAX.

Any help will be appreciated.

Answer

I am wondering how I can send the request to check-email.php via POST instead of GET without any explicit AJAX.

That doesn't even make sense. Since the remote method is facilitated via ajax(), using remote without Ajax is entirely impossible.

the remote request to my check-email.php is sent via GET and not POST

Following the docs, you can use any jQuery .ajax() setting.

So simply set the type to POST...

$( "#myform" ).validate({
    rules: {
        email: {
            required: true,
            email: true,
            remote: {
                url: "check-email.php",
                type: 'POST'
            }
        }
    }
});