I'm studying javascript and json and I need to get my json files from another server. I've done some javascript tests working with local json files but now I'd like to convert all my code to jsonp because I need to work on files that are on another domain. My code is:
function jsonEntity()
{
var richiestaEntity = new XMLHttpRequest();
richiestaEntity.onreadystatechange = function()
{
if(richiestaEntity.readyState == 4)
{
var objectentityjson = {};
window.arrayEntity= []; //creazione dell'array che conterrĂ le entity
objectentityjson = JSON.parse(richiestaEntity.responseText);
arrayEntita = objectentityjson.cards;
return arrayEntita;
}
}
richiestaEntity.open("GET", "myjson.json", true);
richiestaEntity.send(null);
}
How can I work with jsonp instead of local json without loosing the structure of my code?