I want to get data from webpage on another domain but i get this error
No 'access-control-allow-origin' header is present on the requested resource
I have tried CORS example from this blog http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/ but i still get the same error.
I have managed to get the content of the page when i ran it in application (same thing i did in Titanium app, now working in PhoneGap that runs in browser)
This is my script
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;
}
function insertText () {
var artist = [];
var table = document.createElement('TABLE')
var tableBody = document.createElement('TBODY')
table.border = '1'
table.appendChild(tableBody);
var xhr = createCORSRequest('GET', "http://www.rockwerchter.be/en/line-up");
if (!xhr) {
throw new Error('CORS not supported');
}
xhr.open("GET", "http://www.rockwerchter.be/en/line-up");
xhr.send();
xhr.onload = function(){
text = request.responseText;
var regex = new RegExp(".*box-title box-title-h3 mb-05.*", "g");
artist = text.match(regex);
var data = [];
for (var i=0; i<artist.length; i++) {
var tr = document.createElement('TR');
tableBody.appendChild(tr);
artist[i]= artist[i].replace("\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t\t<h2 class=\"box-title box-title-h3 mb-05\">", "");
artist[i]= artist[i].replace("</h2>","");
tr.innerHTML=artist[i];
}
}
}