I would like to alert(httpAccept) outside of the function but this is not possible. All actions must me made inside the httpAcceptResponse(data).
When I consol httpAccess after the getHTTP() I get
Resource interpreted as Script but transferred with MIME type text/html: "http://www.domain.com/httpaccept.php?callback=httpAcceptResponse".
What is a workaround for this?
function requestServerCall(url) {
var head = document.head;
var script = document.createElement("script");
script.setAttribute("src", url);
head.appendChild(script);
head.removeChild(script);
}
var httpAccept = '';
function httpAcceptResponse(data) {
httpAccept = data.token;
}
function getHTTP() {
requestServerCall("http://www.domain.com/httpaccept.php?callback=httpAcceptResponse");
}
getHTTP();
<head>). It's asynchronous, so you need to do anything related to the data in the callback. One way is to pass a callback when you request the data.