Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8680213
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T21:11:27+00:00 2026-06-12T21:11:27+00:00

I am getting some data from the server and displaying on the screen. My

  • 0

I am getting some data from the server and displaying on the screen. My JavaScript is shown below, and the PHP server code follows. My problem is when the database returns null (for instance, the title). PHP recognizes it as NULL, and JavaScript in turn recognizes it as null. I then display it on the screen, and it is not displayed as null, but displayed as “null”. I don’t wish to display the text “null”, but display nothing.

As a workaround, I can replace data.title with ((data.title)?data.title:''). Is this the best way to deal with it?

$.get('server.php',{id:1855},
    function (data)
    {
        //data={"id":"1855","firstname":"Pat","lastname":"Prentice","title":null}
        $('#my_id').html('<dl><dt>Name:</dt><dd>'+data.firstname+' '+data.lastname+'</dd>'+'<dt>Title:</dt><dd>'+data.title+'</dd>');
    },'json');

server.php returns the following:

<?php
$sql_output=array('id'=> 1855, 'firstname'=>'Pat','lastname'=>Prentice,'title'=>NULL);
echo json_encode($array);
?>
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T21:11:28+00:00Added an answer on June 12, 2026 at 9:11 pm

    Will kind of provided the best answer as a comment:

    You could also set a defauly value of ” ” (or anything else) from your
    query, so that it never actually returns null

    Since the data is being pulled from a database, just do:

    SELECT COALESCE(title,'') AS title, bla, bla, bla
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm getting some html data from remote server and before displaying it in the
I am getting some data from my database table. The query I use is
i am getting problem as i have some data in a database tabel file
I'm getting some weird thing happening with my javascript. I'm fetching data from the
I need to get some data from a mysql database.I'm running a php script
I'm sending XML request to some server and getting some response data from it
I am getting some data from a database table tableA and need to return
I'm getting some data from a XML file on my server,here's the parse of
Trying to archive some data from one database table to another over linked server
I have an old program pushing some data from a Microsoft SQL server database

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.