javascript - Parsley ajax 发送 post 变量

标签 javascript php ajax

来自他们的官方文档:

        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/

相关文章:

php - 获取所有新闻和所有评论

javascript - 如何使用 JQuery 中的 data 参数解析 JSON?

ajax获取对Office365 REST Api的请求失败CORS?

javascript - 在发送 ajax 请求之前显示确认信息

php - Codeigniter 运行时没有路由?

PHP函数解析多维数组?

javascript - ReactJS:为什么我的文本区域值总是呈现不可见?

javascript - 选择给定元素之前和之后的 div 内容

javascript - 从 'onblur' 事件中排除表单按钮,JavaScript

javascript - 随机图像点击