Why sendResponse({ helloWorld: sendto }) sending back empty string and not that this.responseText is assigned to sendto variable? How to manage my code properly to achieve sending back this.responseText and not the empty string?
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
**var sendto = 'empty';**
var ccc = new XMLHttpRequest();
ccc.onreadystatechange = function () {
if (this.readyState == 4 && this.status == 200) {
console.log(this.responseText)
**sendto = this.responseText;**
}
}
ccc.open("GET", "http://127.0.0.1:3000/" + request.greeting)
ccc.send();
**sendResponse({ helloWorld: sendto });**
});