Suppose I have a PlainObject:
formData: completed: null limit: "10"
Which I then use in an ajax call:
$.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:
$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?
You can use jquery validation as validator - https://jqueryvalidation.org/