AJAX response undefined
I've checked various posts on this subject and I can't see why I'm getting undefined still for responseText. The returned json should look like {"token": "ghargaeorigjaoregrjarjegijra[pgjpraejgprjgpkfp5p34i5483te8q9rut053"}
function getAuth(username, password) {
let http = new XMLHttpRequest();
let url, method;
let data = {"username": username, "password": password};
url = returnLocation("default");
method = 'POST';
http.open(method, "http://" + url + "/monitor/admin/auth/", true);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Accept", "application/json");
http.send(JSON.stringify(data));
http.onreadystatechange = function() {
if (http.readyState === XMLHttpRequest.DONE && http.status === 200){
setCookie(http.responseText);
}
else if (http.readyState === XMLHttpRequest.DONE && http.status !== 200){
alert(http.statusText);
}
}
}
javascript ajax xmlhttprequest
add a comment |
I've checked various posts on this subject and I can't see why I'm getting undefined still for responseText. The returned json should look like {"token": "ghargaeorigjaoregrjarjegijra[pgjpraejgprjgpkfp5p34i5483te8q9rut053"}
function getAuth(username, password) {
let http = new XMLHttpRequest();
let url, method;
let data = {"username": username, "password": password};
url = returnLocation("default");
method = 'POST';
http.open(method, "http://" + url + "/monitor/admin/auth/", true);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Accept", "application/json");
http.send(JSON.stringify(data));
http.onreadystatechange = function() {
if (http.readyState === XMLHttpRequest.DONE && http.status === 200){
setCookie(http.responseText);
}
else if (http.readyState === XMLHttpRequest.DONE && http.status !== 200){
alert(http.statusText);
}
}
}
javascript ajax xmlhttprequest
1
in cases like this I recommend to log the object (in your casehttp
) in the console usingconsole.log(http)
to find out if there is an attribute named "responseText"
– messerbill
Nov 15 '18 at 13:28
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10
add a comment |
I've checked various posts on this subject and I can't see why I'm getting undefined still for responseText. The returned json should look like {"token": "ghargaeorigjaoregrjarjegijra[pgjpraejgprjgpkfp5p34i5483te8q9rut053"}
function getAuth(username, password) {
let http = new XMLHttpRequest();
let url, method;
let data = {"username": username, "password": password};
url = returnLocation("default");
method = 'POST';
http.open(method, "http://" + url + "/monitor/admin/auth/", true);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Accept", "application/json");
http.send(JSON.stringify(data));
http.onreadystatechange = function() {
if (http.readyState === XMLHttpRequest.DONE && http.status === 200){
setCookie(http.responseText);
}
else if (http.readyState === XMLHttpRequest.DONE && http.status !== 200){
alert(http.statusText);
}
}
}
javascript ajax xmlhttprequest
I've checked various posts on this subject and I can't see why I'm getting undefined still for responseText. The returned json should look like {"token": "ghargaeorigjaoregrjarjegijra[pgjpraejgprjgpkfp5p34i5483te8q9rut053"}
function getAuth(username, password) {
let http = new XMLHttpRequest();
let url, method;
let data = {"username": username, "password": password};
url = returnLocation("default");
method = 'POST';
http.open(method, "http://" + url + "/monitor/admin/auth/", true);
http.setRequestHeader("Content-Type", "application/json");
http.setRequestHeader("Accept", "application/json");
http.send(JSON.stringify(data));
http.onreadystatechange = function() {
if (http.readyState === XMLHttpRequest.DONE && http.status === 200){
setCookie(http.responseText);
}
else if (http.readyState === XMLHttpRequest.DONE && http.status !== 200){
alert(http.statusText);
}
}
}
javascript ajax xmlhttprequest
javascript ajax xmlhttprequest
asked Nov 15 '18 at 13:26
mark1973ryanmark1973ryan
1
1
1
in cases like this I recommend to log the object (in your casehttp
) in the console usingconsole.log(http)
to find out if there is an attribute named "responseText"
– messerbill
Nov 15 '18 at 13:28
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10
add a comment |
1
in cases like this I recommend to log the object (in your casehttp
) in the console usingconsole.log(http)
to find out if there is an attribute named "responseText"
– messerbill
Nov 15 '18 at 13:28
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10
1
1
in cases like this I recommend to log the object (in your case
http
) in the console using console.log(http)
to find out if there is an attribute named "responseText"– messerbill
Nov 15 '18 at 13:28
in cases like this I recommend to log the object (in your case
http
) in the console using console.log(http)
to find out if there is an attribute named "responseText"– messerbill
Nov 15 '18 at 13:28
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10
add a comment |
1 Answer
1
active
oldest
votes
I've used the http.response instead of http.ResponseText
add a comment |
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
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320541%2fajax-response-undefined%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
I've used the http.response instead of http.ResponseText
add a comment |
I've used the http.response instead of http.ResponseText
add a comment |
I've used the http.response instead of http.ResponseText
I've used the http.response instead of http.ResponseText
answered Nov 15 '18 at 14:11
mark1973ryanmark1973ryan
1
1
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53320541%2fajax-response-undefined%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
1
in cases like this I recommend to log the object (in your case
http
) in the console usingconsole.log(http)
to find out if there is an attribute named "responseText"– messerbill
Nov 15 '18 at 13:28
Do you get the value undefined from http.responseText, or do you get an error "unable to access property responseText of undefined" or similar.
– James
Nov 15 '18 at 13:48
I try to JSON.parse and get undefined. When I log console.log(http.responseText) I get undefined. Logging the http object I get: onabort: nullresponse: "{"token":"redacted"}" responseText: "{"token":"redacted"}"
– mark1973ryan
Nov 15 '18 at 14:06
So I have the response I just can't process it.
– mark1973ryan
Nov 15 '18 at 14:07
Thanks for the troubleshooting tip, when you're stuck sometimes you go blank and I'm deploying django in a docker container which makes it a little tougher. I used response instead of repsonseText. Works fine!
– mark1973ryan
Nov 15 '18 at 14:10