Parsley Ajax Sending Post Variables
From their official documentation: Custom ajax validation made simple. parsley-remote-method='POST' to change default GET call. parsley-remote-datatype='jsonp' if you make
Solution 1:
To trigger a remote validator on the field you will need to put both attributes
parsley-remote="http://yoururl.com"
and
parsley-remote-method="POST"
to make the variable submitted in a POST request.
For example:
<input type="text" name="test" value="1" parsley-remote="http://yoururl.com" parsley-remote-method="POST" />
then your script at the back-end has to validate the "test" variable and return 200 response with:
{ "success": "all good!" }
or
{ "error": "your custom message" }
Solution 2:
In newer versions of Parsley.js, you can use data-parsley-remote-options
like so:
data-parsley-remote-options='{
"type": "POST",
"dataType": "jsonp",
"data": {
"token": "value"
}
}'
Put whatever you need to send as a key/value pair in the data
object.
More information in the docs.
Post a Comment for "Parsley Ajax Sending Post Variables"