PDA

View Full Version : Origin null is not allowed by Access-Control-Allow-Origin.



smansakra
02-03-2012, 06:27 PM
i have a code like below

function get_image(image_path){
document.querySelector('#status').innerHTML = 'loading..'; //tambahkan loading text
window.URL = window.URL || window.webkitURL; // Take care of vendor prefixes.
var xhr = new XMLHttpRequest();
xhr.open('GET', image_path, true);
xhr.responseType = 'blob'; //respondnya blob

xhr.onload = function(e) {
if (this.status == 200) {
var blob = this.response;
var img = document.createElement('img');
img.onload = function(e) {
window.URL.revokeObjectURL(img.src); // Clean up after yourself.
};
img.src = window.URL.createObjectURL(blob);
document.body.appendChild(img);
document.querySelector('#status').innerHTML = ''; //hilangkan loading text
}
};
xhr.send();
}

then, i call that function by using this below html button

<input type="button" value="Get image" onclick="get_image('http://mysite.com/Screenshot_html5_form.gif');"/><br/>
<span id="status"></span>

Unfortunatey Chrome and Firefox 10 return origin null,
i see chrome says like this -> XMLHttpRequest cannot load http://mysite.com/Screenshot_html5_form.gif. Origin null is not allowed by Access-Control-Allow-Origin.


So, what should i do????