I am using Ajax where the server queries a database using SELECT someColumn FROM someTable
, returns someColumn to the client, and the client updates an element using $('#someElement').text(someColumn);
Works great unless someColumn returns null, in which the page displays "null" instead of my desired empty string. Originally, I was dealing with this at the database level using SELECT COALESCE(someColumn,'')
, however, am considering changing to the client level using $('someElement').text(someColumn==null?'':someColumn);
I am sure there are other solutions as well. What is the best practice method to display null as nothing?
NULL
for as long as possible - i.e. handle that case in the client.json_encode()
on the data first, server-side. It will generate'text'
, but alsonull
which will achieve the desired result.