Problem with null value

I have written this code…so thst when there in empty input null gets to be sent with ajax.

 var coname=$("#coname").val()!==''?$("#coname").val():null;

And the problem is that when var_dumping the above variable in the server isntead of null I get empty string.

Why that happens?

var coname = $("#coname").val();
if(coname) {
  send ajax
};

if data is a object then u need delete attribute have null value;

ex:

var data = {
  coname :  $("#coname").val()
};
data.coname || delete data.coname;

$.ajax({
  .
  .
  .
  data: data
})

I do not think you solution can be adopted…you see I am not sending only coname with ajax…

There are other variables too.

the data being is sent is an object

var data={"name":x,"lastname"y,coname:.....}

In that case, what manner of solution did you have in mind?

U can try to this code and debug on server to test data from client:

var data = {
  coname :  $("#coname").val()
};
**data.coname || delete data.coname;**

$.ajax({
  .
  .
  .
  data: data
})

Request parameters are always strings. and the string equivalent of NULL is the empty string.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.