AJAX response undefined












0















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);
}
}
}









share|improve this question


















  • 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











  • 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
















0















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);
}
}
}









share|improve this question


















  • 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











  • 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














0












0








0








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);
}
}
}









share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 15 '18 at 13:26









mark1973ryanmark1973ryan

1




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











  • 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





    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













  • 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












1 Answer
1






active

oldest

votes


















0














I've used the http.response instead of http.ResponseText






share|improve this answer























    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%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









    0














    I've used the http.response instead of http.ResponseText






    share|improve this answer




























      0














      I've used the http.response instead of http.ResponseText






      share|improve this answer


























        0












        0








        0







        I've used the http.response instead of http.ResponseText






        share|improve this answer













        I've used the http.response instead of http.ResponseText







        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 15 '18 at 14:11









        mark1973ryanmark1973ryan

        1




        1
































            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%2f53320541%2fajax-response-undefined%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

            Bressuire

            Vorschmack

            Quarantine