I am using AJAX requests (jQuery) for getting collections of data. Some of the endpoints support extra options for filtering out data (eg api.com/users/?name=chr
)
When the data parameter (eg name) is empty, I don't want the request to send it.
I've tried this {name: name !== '' ? name : null}
but the request is sending the 'name' parameter as empty string (eg api.com/users/?name=&anotherparam=value
)
[EDIT]
Because it got marked as duplicated due to the fact that a possible solution would be to remove empty properties from the data object that is sent, I want to clarify that firstly I wanted to use a feature (parameter omitting) of the framework (in that case jQuery) if that exists, which as I state in my answer, does.