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

  • Home
  • SEARCH
  • 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 8296317
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T14:56:51+00:00 2026-06-08T14:56:51+00:00

Still learning and need some help please. This code example checks the validity of

  • 0

Still learning and need some help please.

This code example checks the validity of a url:

function check_URL() {
var url = "http://" + localStorage['t'] + ".somewhere.com";

$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
            "q=select%20*%20from%20html%20where%20url%3D%22"+
            encodeURIComponent(url)+
            "%22&format=xml'&callback=?",
    function(data){
      if(data.results[0]){
        console.log("yes");
      } 
      else { 
      console.log("no");
      alert(url + " is not a valid URL or is down.");

     }
    }
  );

};

It does exactly what I want (and I found it here!). But, I need to check additional urls too.

How can I do that with an .each? I’m just too new to this stuff and an example will help my learning.

Also, if it helps, the domain “somewhere” used in the example will always be the same.

UPDATE: Thanks to Thiago who helped point me in the right direction.

function check_URL() {

var url = "http://" + localStorage['t'] + ".somewhere.com";
var url1 = "http://" + localStorage['t1'] + ".somewhere.com";
var url2 = "http://" + localStorage['t2'] + ".somewhere.com";
var url3 = "http://" + localStorage['t3'] + ".somewhere.com";

var urlArray = ['url', 'url1', 'url2','url3'];
$(urlArray).each(function (urlItem) {
$.getJSON("http://query.yahooapis.com/v1/public/yql?"+
            "q=select%20*%20from%20html%20where%20url%3D%22"+
            encodeURIComponent(urlItem)+
            "%22&format=xml'&callback=?",
    function(data){
      if(data.results[0]){
        console.log("yes");
      } 
      else { 
      console.log("no");
      alert(url + " is not a valid URL or is down.");

     }
    }
  );
});
};

This seems to find any of the urls that don’t validate but the alert is broken.

Ideas?

Thanks!

FINAL UPDATE: Working solution posted below.

  • 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-08T14:56:53+00:00Added an answer on June 8, 2026 at 2:56 pm

    Here’s the solution I used. Thanks to @BaylorRae’ for the guidance!

    function check_URL() {
    
      var url = "http://" + localStorage['t'] + ".somewhere.com";
      var url1 = "http://" + localStorage['t1'] + ".somewhere.com";
      var url2 = "http://" + localStorage['t2'] + ".somewhere.com";
      var url3 = "http://" + localStorage['t3'] + ".somewhere.com";
    
      var urlArray = [url, url1, url2, url3],
          invalidUrls = [];
    
      $.each(urlArray, function (i, urlItem) {
        $.getJSON("http://query.yahooapis.com/v1/public/yql?"+
        "q=select%20*%20from%20html%20where%20url%3D%22"+
        encodeURIComponent(urlItem)+
        "%22&format=xml'&callback=?",
        function(data){
          if(data.results[0]){
            console.log("yes");
          } 
          else { 
            invalidUrls.push(urlItem);
          }
        }
        );
      });
    
      return invalidUrls;
    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am still learning RegEx so I need some help on this one. Rules
I'm still learning how to use SQL, and I need some help creating this
I'm still learning how to design databases for my applications and need some help
Still learning WPF....thanks for any help. Is there any way to Refactor this: <ListBox
I need help again with some regular expressions I'm trying to do (still under
I'm still learning Java/Android development and I need some guidance to implement an Async
Can anyone help me, I'm a n00b at this and still learning. I simply
Still learning Objective-C / iPhone SDK here. I think I know why this wasn't
Still learning CSS so pardon if this is obvious - I am building a
Still learning JSP Web Applications here. I have been doing this for a while

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.