0

I have a url https://blah/configs.ini

It basically looks like this:

[cdmglobal]
collectionHomepageImage = "upload"
customLandingPageAltText = ""
customLandingPageImage = "images/landingpage/small-monographiiif2.jpg
...
...

I need the name of that customLandingPageImage. My plan was to put it into a string and then grab the bit after '/images/landingpage' until I get to '.jpg'

I've tried this

let newSource = "http://blah/configs.ini";
fetch(newSource)
.then(function(response) {
    let responseString = response.text();
    console.log(responseString);
}).catch(function() {
    console.log("error");
});

Now in Chrome dev tools, it shows me:

Promise
    __proto__: Promise
        [[PromiseStatus]]: "resolved"
        [[PromiseValue]]: "[cdmglobal]↵collectionHomepageImage = "upload"↵customLandingPageAltText = ""↵customLandingPageImage = "images/landingpage/small-monographiiif2.jpg

I really just want that promiseValue but it only returns it in the form of a promise value, not a string.

James B
  • 432
  • 5
  • 22

2 Answers2

2

This should work;

let newSource = "http://blah/configs.ini";
fetch(newSource)
.then(function(response) {
    response.text().then(function(responseString) { 
        console.log(responseString);
    });
}).catch(function() {
    console.log("error");
});
alexandercannon
  • 544
  • 5
  • 24
0

Why is it that I can try to figure this out for an hour and then solve it 12 seconds after posting to stack overflow?

Solution:

        fetch(newsource)
        .then(function(response) {
            return response.text();
        }).then(function(text) {
            console.log(text);
        }).catch(function() {
            console.log("error");
        });
James B
  • 432
  • 5
  • 22
  • Is the variable bleh mandatory in your code ? I think you can remove it and just call console.log(text) instead – cocool97 Aug 29 '19 at 20:35