# Getting a .status code 0 from an HTTP request

**URL:** <https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845>\
**Category:** General\
**Tags:** ajax, http, javascript, html\
**Created:** [July 3, 2017, 8:32pm UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845 "2017-07-03T20:32:33Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![FifthEmpire](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fifthempire/32/66284_2.png) [@FifthEmpire](https://forum.freecodecamp.org/u/FifthEmpire)\
**Post date:** [July 3, 2017, 8:32pm UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/1 "2017-07-03T20:32:33Z")

</div>

I’m trying to make a request to the Darksky API to show the local weather ([a freeCodeCamp project](https://www.freecodecamp.org/challenges/show-the-local-weather)).

To get the response from the server, I’m following the [Getting Started](https://developer.mozilla.org/en-US/docs/AJAX/Getting_Started) with Ajax guide from Mozilla.  
As the response of a request from DarkSky is in JSON (if I’m not wrong. click [here](https://darksky.net/dev/docs/forecast) for more information), I diced to use the first example of the Mozilla’s guide. The basic code from the article is shown below. In this example, the code is ‘GETting’ the information from a local file, ‘test.html’:

 Make a request 

```
<script>
    (function() {
        var httpRequest;
        document.getElementById("ajaxButton").addEventListener('click', makeRequest);

        function makeRequest() {
            httpRequest = new XMLHttpRequest();

            if (!httpRequest) {
                alert('Giving up :( Cannot create an XMLHTTP instance');
                return false;
            }
            httpRequest.onreadystatechange = alertContents;
            httpRequest.open('GET', 'test.html');
            httpRequest.send();
        }

        function alertContents() {
            if (httpRequest.readyState === XMLHttpRequest.DONE) {
                if (httpRequest.status === 200) {
                    alert(httpRequest.responseText);
                } else {
                    alert('There was a problem with the request.' + httpRequest.status);
                }
            }
        }
    }) ();
</script>

```

Trying to get my response from DarkSky, a just changed the `httpRequest.open('GET', 'test.html');` to `httpRequest.open('GET', 'https://api.darksky.net/forecast/my_personal_key/0.0000,-111.1111');`. But I got a **status code id 0** from my http request.

Making a search, I discovered that **there is no code 0 from an http request** and that W3C address some possibilities to this code. [This](https://stackoverflow.com/questions/3825581/does-an-http-status-code-of-0-have-any-meaning/#answer-26451773) answer and [that](https://stackoverflow.com/questions/872206/http-status-code-0-what-does-this-mean-for-fetch-or-xmlhttprequest/#answer-905878) has more information about that.

I’m trying to do that in a local file; using WebStorm IDE (updated); Chrome as a browser; and from Brazil.

Could someone help me get the correct answer from the DarkSky API using the **vanilla JavaScript** (no jQuery, please).

Thank you for your interest in help me.

---

<div class="post-metadata">

**Author:** ![Marmiz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/marmiz/32/74845_2.png) [@Marmiz](https://forum.freecodecamp.org/u/Marmiz)\
**Post date:** [July 4, 2017, 2:30am UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/2 "2017-07-04T02:30:17Z")

</div>

As far as I know, there is no `status cod 0` in http responses, so it’s definitely a Dark Sky error of some sort.

You should check their documentation for further assistance.  
So far I’ll check:

1 - Do you have a valid key?  
2 - Are you having some errors in console (like CORS or No  
-Header)

---

<div class="post-metadata">

**Author:** ![FifthEmpire](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fifthempire/32/66284_2.png) [@FifthEmpire](https://forum.freecodecamp.org/u/FifthEmpire)\
**Post date:** [July 4, 2017, 3:12am UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/3 "2017-07-04T03:12:21Z")

</div>

1. Yes. When I use the link - with my key and coordinates - in my browser, it seems that the browser gives me the information.

2. Yes. the following error:

> XMLHttpRequest cannot load [How Dark Sky users can use the Apple Weather app - Apple Support](https://api.darksky.net/forecast/my_personal_key/-21.766035,-43.347504). No ‘Access-Control-Allow-Origin’ header is present on the requested resource. Origin ‘[http://localhost:63342](http://localhost:63342)’ is therefore not allowed access.

Sorry, but I didn’t check the console for error. 😮 Thank you very much for your help. 🕺 I can’t check it now, but tomorrow I’ll work on this problem. I’ll read the CORS guide on Mozilla and update this post. I was stuck on this problem for some days. 😊

---

<div class="post-metadata">

**Author:** ![Marmiz](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/marmiz/32/74845_2.png) [@Marmiz](https://forum.freecodecamp.org/u/Marmiz)\
**Post date:** [July 4, 2017, 3:49am UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/4 "2017-07-04T03:49:06Z")

</div>

Simply parse the request through [crossorigin.me](http://crossorigin.me/) and you’ll (hopefully) be ready to go.

Basically change the url request from this:  
`https://api.darksky.net/forecast/my_personal_key/0.0000,-111.1111`

to this:  
`https://crossorigin.me/https://api.darksky.net/forecast/my_personal_key/0.0000,-111.1111`

and let them handle the CORS request for you.

---

<div class="post-metadata">

**Author:** ![FifthEmpire](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/fifthempire/32/66284_2.png) [@FifthEmpire](https://forum.freecodecamp.org/u/FifthEmpire)\
**Post date:** [July 4, 2017, 5:28pm UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/5 "2017-07-04T17:28:44Z")

</div>

It Worked. 😄 Thank you very much for your help. I’ll try to learn more about CORS too, but now I can go on with my project. 🏋️‍♂️

---

<div class="post-metadata">

**Author:** ![ILM](https://sea3.discourse-cdn.com/freecodecamp/user_avatar/forum.freecodecamp.org/ilm/32/363239_2.png) [@ILM](https://forum.freecodecamp.org/u/ILM)\
**Post date:** [January 16, 2021, 11:33am UTC](https://forum.freecodecamp.org/t/getting-a-status-code-0-from-an-http-request/133845/6 "2021-01-16T11:33:13Z")

</div>


