I've got a short javascript script that I'm running with node (e.g. node runScript.js
). Within it, I'm using tiptoe, and I've tried various ways of retrieving an xml file without success.
tiptoe(
function getESData() {
var json;
// get the json data.
for (var i = 0; i < json.hits.hits.length; i++) {
for (var multiId = 0; multiId < json.hits.hits[i]._source.multiverseids.length; multiId++) {
var priceUrl = "http://partner.tcgplayer.com/x3/phl.asmx/p?pk=TCGTEST&s="+setName+"&p="+json.hits.hits[i]._source.name
console.log("fetching " +priceUrl );
// attempt 1:
var x = new XMLHttpRequest();
console.log("working"); // THIS CONSOLE LOG NEVER SHOWS UP.
x.open("GET", priceUrl, true);
console.log("working");
x.onreadystatechange = function() {
if (x.readyState == 4 && x.status == 200)
{
console.log(x.responseXML);
}
};
x.send();
// attempt 2:
$.ajax({
url: priceUrl,
success: function( data ) {
console.log(data);
}
});
// attempt 3:
$.get(priceUrl, function(data, status){
console.log("Data: " + data + "\nStatus: " + status);
});
}
}
});
}
);
All of these methods fail silently (obviously I comment out all but one when testing, I don't use all three at once), after printing the first console.log where I log the url to make sure it works. (The urls with the variables resolve to something like this: http://partner.tcgplayer.com/x3/phl.asmx/p?pk=TCGTEST&s=Ice Age&p=Arnjlot's Ascent
which absolutely returns xml when I test it in a browser, so I know that's working). Is it something with tiptoe?
edit: attempt 4:
$().ready(function () {
console.log('working');
$.get(priceUrl, function (data) {
console.log(data);
});
});
This also fails before the 'working' log shows up in my console. Not sure that it matters, but I'm using a git bash console for this, also.
edit 2: The answer was to use request
, in the following way:
request(priceUrl, function(error, response, body) {
if (!error && response.statusCode == 200) {
console.log(body);
}
})
That worked perfectly.