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

The Archive Base Latest Questions

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

I’m trying to write a simple AJAX method to get a list of videos

  • 0

I’m trying to write a simple AJAX method to get a list of videos from Vimeo without using jQuery. I realize that I must use the JSONP format because it is a cross-domain request. However, the result returned is always 200 OK and it is always empty. Here’s my method:

var httpRequest = new XMLHttpRequest();

httpRequest.open("GET", "http://vimeo.com/api/v2/channel/staffpicks/videos.json?callback=?", true);
httpRequest.send();

httpRequest.onreadystatechange = function () {
    if (httpRequest.readyState == 0) {
        console.log("0");
    }
    if (httpRequest.readyState == 1) {
        console.log("1");
    }
    if (httpRequest.readyState == 2) {
        console.log("2");
    }
    if (httpRequest.readyState == 3) {
        console.log("3");
    }
    if (httpRequest.readyState == 4 && httpRequest.status == 200) {
        console.log("4");
    }
    if (httpRequest.readyState == 4 && httpRequest.status == 404) {
        console.log("5");
    }
};

The console logs 2, but not 0, 1, 3, 4, or 5. It’s always just 2.

By the way, this doesn’t have to be a Vimeo request. The only reason I’m using a Vimeo URL is because I don’t know how else to test an AJAX request than to hit an actual site.

  • 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:13:42+00:00Added an answer on June 8, 2026 at 2:13 pm

    In retrospect, this is a pretty poor question. It’s really two or three questions:

    1. Why does my cross-domain request to Vimeo return 200 OK but it is empty?
    2. Why does the console log 2 but not 0, 1, 3, 4, or 5?
    3. How else can I test an AJAX request other than to hit an actual site?

    The answers to questions one and two are below, posted by Alexander and Eswar Rajesh Pinapala, respectively. The answer to question three is to request a local JavaScript file.

    One thing I struggled with that others might benefit from is that httpRequest.status throws an exception when httpRequest.readyState is 0 or 1. So this doesn’t work:

    httpRequest.onreadystatechange = function () {
        alert(httpRequest.readyState + httpRequest.status);
    };​
    

    Here is what worked for me:

    try {
        httpRequest = new XMLHttpRequest();
        console.log("0");
    
        httpRequest.open(options.method, options.url, true);
        console.log("1");
    
        httpRequest.send();
    } catch (err) {
        console.log(err.name + ': ' + err.message + ' (line ' + err.lineNumber + ')');
    
        return false;
    }
    
    httpRequest.onreadystatechange = function () {
        if (httpRequest.status === 404) {
            this.onreadystatechange = null;
    
            return false;
        }
    
        if (httpRequest.readyState === 2) {
            console.log("2");
        } else if (httpRequest.readyState === 3) {
            console.log("3");
        } else if (httpRequest.readyState === 4) {
            console.log("4");
    
            return true;
        }
    };
    

    The reason for wrapping the constructor, open, and send methods in a try…catch statement is so you can catch any errors that result from a bad filename or something. These will blow up before it ever gets into the onreadystatechange function. The onreadystatechange property is only initialized once the send method has been called.

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

Sidebar

Related Questions

I am trying to find ID3V2 tags from MP3 file using jid3lib in Java.
I'm trying to convert HTML to plain text. I get many &\#8217; &\#8220; etc.
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I'm making a simple page using Google Maps API 3. My first. One marker
I am reading a book about Javascript and jQuery and using one of the
I am using jsonparser to parse data and images obtained from json response. When
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
I'm new to using the Perl treebuilder module for HTML parsing and can't figure
link Im having trouble converting the html entites into html characters, (&# 8217;) i

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.