Could Someone Please Advise Where I'm Going Wrong

Hi,

I’m trying to learn how to use API’s, as a starter project I have decided to try and use EA’s FUT API.

The code I have is:

var searchInput = document.getElementById("userInput").value;
futSearchResult();

function futSearchResult() {
    var request = new XMLHttpRequest();
    request.open('GET', 'https://www.easports.com/fifa/ultimate-team/api/fut/item?name=' + searchInput.value, true);
        request.onload = function () {

            var data = JSON.parse(this.response);

            if (request.status >= 200 && request.status < 400) {
            console.log(commonName);
            });
            } else {
            console.log('error');
            }
        }
    };
};

request.send();

Could anyone please advise where I’m going wrong with this please?

Thanks

You have already assigned searchInput as a value of the input.

var searchInput = document.getElementById("userInput").value;

But, again, in the request.open(), you used searchInput.value.

Hope, it helps.

Thank you for your help @picklu

1 Like