I am new to jquery and don't know to fetch json data from another domain(Cross domain).
function createCORSRequest(method, url){
var xhr = new XMLHttpRequest();
if ("withCredentials" in xhr){
xhr.open(method, url, true);
} else if (typeof XDomainRequest != "undefined"){
xhr = new XDomainRequest();
xhr.open(method, url);
} else {
xhr = null;
}
return xhr;
}
var request = createCORSRequest("get", "http://www.stackoverflow.com/");
if (request){
request.onload = function() {
// ...
};
request.onreadystatechange = handler;
request.send();
}
I found this program from here Ways to circumvent the same-origin policy
This is saying by using above code we can access cross domain json data.
I copied the code. This is saying handler is undefined
I don't know how to define handler .
I also don't know what to write inside request.onload
where I will get the json result
Please help
Thanks in advance