jquery - Javascript: " No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. " -



jquery - Javascript: " No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. " -

i need write web page can info need javascript. sever bamboo sever , trying utilize rest api of theirs in javascript. https://developer.atlassian.com/display/bamboodev/rest+apis

the weird part can perform requests typing link in browser, or curl command in termanal. works via python script. can receive info methods mentioned in paragraph. it's when go javascript, doesn't work anymore.

i have been next info in below link making cors request. http://www.codeproject.com/articles/185506/ajax-cross-origin-http-request

attached below code. wondering if have missed something.

<!doctype html> <html> <head> <meta http-equiv="access-control-allow-origin" content="*"> <meta content="text/html;charset=utf-8" http-equiv="content-type"> <meta content="utf-8" http-equiv="encoding"> <script src="jquery-1.11.1.js"></script> <script src="crypto-js.js"></script> <script type="text/javascript"> function showresponse (response) { response = response; if (this && this.url && (typeof(this.url) == "string")) { var anchor = jquery("#url"); anchor.text(this.url.tostring()); anchor.attr('href', this.url.tostring()); } jquery("#output").text(json.stringify(response, null, ' ')); } </script> <script type="text/javascript"> console.log("a") var cor = null; // cor stands cross-origin request if (window.xmlhttprequest) { console.log("support xmlhttprequest"); cor = new xmlhttprequest(); }else { console.log("your browser not back upwards cross-origin request!"); } if("withcredentials" in cor){ cor.open('get', 'http://bamboo.example.com/rest/api/latest/stuff', true); cor.withcredentials = true; cor.setrequestheader('authorization', 'basic encoded_stuff'); cor.send(); } cor.onload = function(){ var responsetext = xhr.responsetext; console.log(responsetext); }; cor.onerror = function() { console.log('there error!'); }; </script> </head> <body> <div>url:<a id="url"></a></div> <hr> <div> <pre id="output"> <!-- content appear here --> </pre> </div> </body> </html>

the chrome console shows "no 'access-control-allow-origin' header nowadays on requested resource. origin 'null' hence not allowed access." result along 401 status.

was wondering if missing code?

thank you

it seems you're sending request rest api link html file that's not on same domain. since there's no "access-control-allow-origin" header on link , you're sending request different domain, security reasons, won't coherent response it, instead error , 401 error since you're unauthorized @ contents of link.

there's unfortunately no way around that; link not meant requested outside domains.

javascript jquery html ajax

Comments

Popular posts from this blog

php - Android app custom user registration and login with cookie using facebook sdk -

django - Access session in user model .save() -

php - .htaccess Multiple Rewrite Rules / Prioritizing -