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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T19:35:19+00:00 2026-05-28T19:35:19+00:00

I have a jQuery search script based on the Bing API. When a user

  • 0

I have a jQuery search script based on the Bing API. When a user searches and their are results for their query they are displayed without a problem. However when there are no results for their search then the page is just blank.

How can I add a message in such as “No results found.” when there are no results to prevent having a blank page?

My current code is:

$(document).ready(function(){
    function search(){
        $.ajax({
            type:"GET",
            url:"http://api.bing.net/json.aspx?AppId=AppIdHere&Query=SearchTermsHere&Sources=Web&Adult=Strict&Web.Count=10&JsonType=callback&JsonCallback=?",
            dataType:"jsonp",
            success:function(query){
                $("#results").html(results(query));
            }
        });
    }
    function results(response){
        var output=[];
        $.each(response.SearchResponse.Web.Results,function(i,result){
            output.push('<a href="'+result.Url+'" class="result"><div class="title">'+result.Title+'</div><div class="url">'+result.DisplayUrl+'</div><div class="desc">'+result.Description+'</div></a>');
        });
        return output.join('');
    }
    search();
});
  • 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-28T19:35:20+00:00Added an answer on May 28, 2026 at 7:35 pm

    Change the return line of the results function to:

    return (output.length == 0 ? 'No results found.' : output.join(''));
    

    === UPDATE ===

    If you have an javascript error, change the results function to:

    function results(response){
        if (typeof response.SearchResponse.Web.Results == 'undefined') {
            return 'No results found.';
        }
        var output=[];
        $.each(response.SearchResponse.Web.Results,function(i,result){
            output.push('<a href="'+result.Url+'" class="result"><div class="title">'+result.Title+'</div><div class="url">'+result.DisplayUrl+'</div><div class="desc">'+result.Description+'</div></a>');
        });
        return output.join('');
    }
    

    or you have to add an error-handler:

        $.ajax({
            ...,
            error:function(){
                $("#results").html('No results found.');
            }
        });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a search script written in jQuery. To submit a query a user
I have a jQuery search script that uses tabs for the user to define
I have a jQuery search script that uses tabs for the user to define
I have a jQuery search script that uses tabs for the user to define
I have a Google Instant style search script written in jQuery. When the user
I have a Google Instant style search script written in jQuery. When a user
I have a Google Instant style search script written in jQuery. When a user
I have a jQuery search script that uses tabs for the user to define
I have a jQuery search script that uses tabs for the user to define
I have a jQuery search that gets a search term from the user and

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.