来自他们的官方文档:
Custom ajax validation made simple.
parsley-remote-method="POST" to change default GET call.
parsley-remote-datatype="jsonp" if you make cross domain ajax call and expect jsonp
Parsley will accept these valid returns with a 200 response code: 1, true, { "success": "..." } and assume false otherwise
You can show frontend server-side specific error messages by returning { "error": "your custom message" } or { "message": "your custom message" }
但是,如果我想在 post 请求中发送一个变量,我该怎么办?
最佳答案
要在字段上触发远程验证器,您需要放置两个属性
parsley-remote="http://yoururl.com"
和
parsley-remote-method="POST"
使变量在 POST 请求中提交。
例如:
<input type="text" name="test" value="1" parsley-remote="http://yoururl.com" parsley-remote-method="POST" />
然后您的后端脚本必须验证“test”变量并返回 200 响应:
{ "success": "all good!" }
或
{ "error": "your custom message" }
关于javascript - Parsley ajax 发送 post 变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21391978/