Have posted before but I think I was a little too specific to gain much interest Original. I am new to javascript and AJAX and have found it difficult to find a simple answer to this question. My goal is to simply parse some remote JSON, giving me an object which I can then use in the rest of application.
The problem I am having is keeping this object alive (getting data using XMLHttpRequest it is only populated during the callback function). I have jQuery available if this eases the answer. The javascript is part of a google chrome extention and does have the right permissions to access the remote JSON.
Hope someone can help
Edit; code from original post + Scott M's answer
var createdDate;
function checkDomainRegistrationLength(url) {
var serverName = urlToServerName(url);
var xhr = new XMLHttpRequest();
xhr.open("GET", "eg.json", false); //Code now working, was set to async
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
var resp = JSON.parse(xhr.responseText);
createdDate = resp.WhoisRecord.audit.createdDate;
}
}
xhr.send();
return createdDate;
}
assign the returned object to a global variable. You can then access it throughout the application.
sorry for not seeing the jquery reference earlier, or i would have included this in the answer.