1

I'd like to access the JSON on

"https://blockchain.info/tx-index/"+txs[i]+"?format=json"

But each time I try to access it with the request, http, or https modules, I can never seem to get any information. The callback is never called, and as near as I can tell, the function doesn't return anything.

Since I'm apparently an idiot in javascript, can you help me out?

Edit: I also tried another method described on here, but it doesn't seem to work either. It always returns undefined.

function httpGet(url)   {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET",url,false);
    xmlHttp.send();
    return xmlHttp.resonpose;
}

Edit: Full loop code:

        index = 0;
        txs = info.x.txIndexes;
        for (i = 0; i < txs.length; i++)    {
            console.log(i);
            request.get("https://blockchain.info/tx-index/"+txs[i]+"?format=json&cors=true", function(error,response,body)  {
                console.log("body");
                txs[index] = JSON.parse(body);
                index++;
            });
            var time = Date.now() + 1000;
            while (Date.now() < time)
                var a = true;
            txs[i] = txt;
        }
2
  • I've tried several different versions. I'll post the most recent. Commented Aug 2, 2015 at 20:06
  • I have actually loaded said module. Every time I try to use it it returns undefined. Commented Aug 2, 2015 at 20:09

1 Answer 1

1
function httpGet(url)   {
    var xmlHttp = new XMLHttpRequest();
    xmlHttp.open("GET",url,false);
    xmlHttp.send();
    return xmlHttp.resonpose;
}

resonpose is spelt response, but the more generally useful property name is responseText.


Your attempt to use request.get is failing for a completely different reason, but that is covered by this question as your load event handler is using the wrong value for i.

Sign up to request clarification or add additional context in comments.

2 Comments

Whoops, transcription typo :)
Weird. Returning response results in undefined. Returning responseText results in the correct result. Thank you!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.