[英]How to preserve NULL values in jQuery ajax POST sent to PHP script?
Suppose I have a PlainObject: 假设我有一个PlainObject:
formData: completed: null limit: "10"
Which I then use in an ajax call: 然后在ajax调用中使用它:
$.ajax({
type: 'post',
url: SomeEndpoint.php,
data: formData,
}).done(function (response) { do stuff }
The POST value in SomeEndpoint.php receives all values as empty strings: SomeEndpoint.php中的POST值将所有值接收为空字符串:
$completed = $_POST['completed'] ?? null; // ""
$limit = $_POST['limit'] ?? null; // "10"
How can I preserve the typing? 如何保存打字? What's the best way to validate typing if an endpoint validates that a variable is either NULL or an Int/Bool? 如果端点验证变量是NULL还是Int / Bool,验证类型的最佳方法是什么?
You can use jquery validation as validator - https://jqueryvalidation.org/ 您可以使用jquery验证作为验证器-https: //jqueryvalidation.org/
Options - https://jqueryvalidation.org/category/plugin/ 选项-https: //jqueryvalidation.org/category/plugin/
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.