假设我有一个PlainObject:
formData:
completed: null
limit: "10"
然后我在 ajax 调用中使用:
$.ajax({
type: 'post',
url: SomeEndpoint.php,
data: formData,
}).done(function (response) { do stuff }
SomeEndpoint.php 中的 POST 值将所有值作为空字符串接收:
$completed = $_POST['completed'] ?? null; // ""
$limit = $_POST['limit'] ?? null; // "10"
如何保留键入内容?如果终结点验证变量是 NULL 还是 Int/Bool,验证类型的最佳方法是什么?
你可以使用 jquery 验证作为验证器 - https://jqueryvalidation.org/
选项 - https://jqueryvalidation.org/category/plugin/