Is there any way to edit the $ .ajax function so that it includes the "date" property when it receives a value, and removes it when it does not receive it? that is, dynamically? Example:
When the variable date has value:
var parametro = "{id: "1"}";
$.ajax({
type: "POST",
url: url,
data: parametro ,
async: async,
...
When it has no value:
var parametro = "";
$.ajax({
type: "POST",
url: url,
async: async,
...
So my idea is something that works like:
$.ajax({
type: "POST",
url: url,
if(parametro)
{
data: parametro,
},
async: async,
...
I've tried to pass as:
data: undefined ,
data: "",
data: null ,
But nothing works. The only way is bypassing the "data" property altogether. I also did not find anything similar.
One more thing, building two versions of the function, as above, is not an option! I need to do dynamically.
Thank you.