Why the “Uncaught ReferenceError:” when making my HTTP request?












0


















"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





See link below for a screenshot of the errors, but here's what I'm getting:




  1. An Uncaught ReferenceError on line 12 where my onreadystatechange is.

  2. I also get an error saying 'responseMethod' isn't defined at
    makeRequest nor when I call it.

  3. Also getting an error on the very last line for some reason.


screenshot










share|improve this question

























  • The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

    – Bergur
    Jan 20 at 0:47











  • You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

    – melpomene
    Jan 20 at 1:07
















0


















"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





See link below for a screenshot of the errors, but here's what I'm getting:




  1. An Uncaught ReferenceError on line 12 where my onreadystatechange is.

  2. I also get an error saying 'responseMethod' isn't defined at
    makeRequest nor when I call it.

  3. Also getting an error on the very last line for some reason.


screenshot










share|improve this question

























  • The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

    – Bergur
    Jan 20 at 0:47











  • You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

    – melpomene
    Jan 20 at 1:07














0












0








0


0









"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





See link below for a screenshot of the errors, but here's what I'm getting:




  1. An Uncaught ReferenceError on line 12 where my onreadystatechange is.

  2. I also get an error saying 'responseMethod' isn't defined at
    makeRequest nor when I call it.

  3. Also getting an error on the very last line for some reason.


screenshot










share|improve this question



















"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





See link below for a screenshot of the errors, but here's what I'm getting:




  1. An Uncaught ReferenceError on line 12 where my onreadystatechange is.

  2. I also get an error saying 'responseMethod' isn't defined at
    makeRequest nor when I call it.

  3. Also getting an error on the very last line for some reason.


screenshot






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "OMMITTED FOR PRIVACY REASONS"; // Replace "APIKEY" with your own API key; otherwise, your HTTP request will not work
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();






javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 20 at 1:06









melpomene

60.3k54693




60.3k54693










asked Jan 20 at 0:11









MichaelMichael

33




33













  • The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

    – Bergur
    Jan 20 at 0:47











  • You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

    – melpomene
    Jan 20 at 1:07



















  • The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

    – Bergur
    Jan 20 at 0:47











  • You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

    – melpomene
    Jan 20 at 1:07

















The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

– Bergur
Jan 20 at 0:47





The code looks correct and works with another api, for example: pokeapi.co/api/v2/pokemon/ditto

– Bergur
Jan 20 at 0:47













You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

– melpomene
Jan 20 at 1:07





You're not getting three different errors. Uncaught ReferenceError: responseMethod is not defined is a single error message.

– melpomene
Jan 20 at 1:07












1 Answer
1






active

oldest

votes


















0














Your code looks good. I just replaced your code with my api key and everything worked (see below).



Can you be more specific about the browser where you get an error?
I tried in the latest chrome and firefox and there is no problem.






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();








share|improve this answer
























  • I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

    – Michael
    Jan 20 at 20:45













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272491%2fwhy-the-uncaught-referenceerror-when-making-my-http-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














Your code looks good. I just replaced your code with my api key and everything worked (see below).



Can you be more specific about the browser where you get an error?
I tried in the latest chrome and firefox and there is no problem.






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();








share|improve this answer
























  • I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

    – Michael
    Jan 20 at 20:45


















0














Your code looks good. I just replaced your code with my api key and everything worked (see below).



Can you be more specific about the browser where you get an error?
I tried in the latest chrome and firefox and there is no problem.






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();








share|improve this answer
























  • I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

    – Michael
    Jan 20 at 20:45
















0












0








0







Your code looks good. I just replaced your code with my api key and everything worked (see below).



Can you be more specific about the browser where you get an error?
I tried in the latest chrome and firefox and there is no problem.






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();








share|improve this answer













Your code looks good. I just replaced your code with my api key and everything worked (see below).



Can you be more specific about the browser where you get an error?
I tried in the latest chrome and firefox and there is no problem.






"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();








"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();





"use strict";

(function() {
var url = "http://api.openweathermap.org/data/2.5/weather?q=London,England";
var apiKey = "4ff5002c91520701ec111b6082de9387"; // This key might expire soon.
var httpRequest;
makeRequest();

// create and send an XHR request
function makeRequest() {
httpRequest = new XMLHttpRequest();
httpRequest.onreadystatechange = responseMethod;
httpRequest.open('GET', url + '&appid=' + apiKey);
httpRequest.send();
}
// handle XHR response
function responseMethod() {
if (httpRequest.readyState === 4) {
console.log(httpRequest.responseText);
}
}
})();






share|improve this answer












share|improve this answer



share|improve this answer










answered Jan 20 at 3:13









sanjeevsanjeev

8114




8114













  • I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

    – Michael
    Jan 20 at 20:45





















  • I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

    – Michael
    Jan 20 at 20:45



















I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

– Michael
Jan 20 at 20:45







I'm using Chrome as well. localhost:3000 I'm just as stumped as anyone else here. For what it's worth this is what I'm practicing with: linkedin.com/learning/building-web-applications-with-ajax/…

– Michael
Jan 20 at 20:45




















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54272491%2fwhy-the-uncaught-referenceerror-when-making-my-http-request%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Liquibase includeAll doesn't find base path

How to use setInterval in EJS file?

Petrus Granier-Deferre