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 7070973
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T05:37:52+00:00 2026-05-28T05:37:52+00:00

Quick question: I’m using jquery ajax to call a page that returns some json

  • 0

Quick question:

I’m using jquery ajax to call a page that returns some json data. Sometimes it returns full of data and sometimes it returns empty as [].

I want the script to do different things if it comes back empty[] or with data. Everything is working fine when it returns with data, but I can’t seem to get things to work when it returns empty as []. Here’s what i have:

success: function (returndata){
      if (returndata === null)
      {
          $("#versionBox").remove();
      }
 else {
        $.each(returndata, function()
               {
                   var tag = this["name"];
                   var linkname = "textdisplay.php?flag=<?php echo $fs; ?>&ed=" + tag;
                       $('#versionBox').append("<p><a href='" + linkname + "'>" +  tag + "</a></p>");
               });

      }

But null doesn’t seem to be the correct way to describe [] because the first part of this script isn’t working.

Thanks for your advice.

  • 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-05-28T05:37:53+00:00Added an answer on May 28, 2026 at 5:37 am

    First, check if it’s an array Check if object is array?, then if its returndata.length == 0. Done & done!

    if( Object.prototype.toString.call( returnData ) === '[object Array]' ) {
        if(returnData.length == 0)
            alert( 'it is []' );
    }
    

    The “is it an array” check isn’t very satisfying, I know…

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Quick question. For some reason links referencing the home page contain an extra /web/guest/home
Quick question, does Kohana (version 3) automatically escape data that is passed into ORM::factory.....
quick question about using ORMLite. I am trying to make sure that my implementation
Quick question. What do you think, I have a few sites that use a
Quick question. There is a legacy website (that is not under my control and
Quick question regarding CSS and the browser. I tried searching SO and found some
Quick question, If I want to document some code on a basic HTML and
Quick question playing with PL SQL it seems that the tables column was named
quick question. I am trying to use either javascript, jquery, or php to make
quick question here. Is there any Wordpress 3.0 documentation available? Some kind of list

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.