javascript - unable to resolve access control issue -


this pretty known standard error unable fix same using existing stackoverflow posts.

xmlhttprequest cannot load https://myserver.com/context/
response preflight request doesn't pass access control check:
no 'access-control-allow-origin' header present on requested resource.
origin 'https://www.otherwebsite.com' therefore not allowed access.
response had http status code 405.

following code have -

function setheader(xhr) {     xhr.setrequestheader("access-control-allow-origin", "*"); }  var url = "https://myserver.com/context/"; $.ajax({     url: url,     type: 'get', datatype:'json',     success: function(data) {         _this.question(data.question);         _this.questionid(data.questionid);         _this.choices(data.choices);     }, error: function() {         console.log("error in getting microquestion");     },     beforesend: setheader }); 

the “response preflight request… had http status code 405.” message indicates, start, https://myserver.com/context/ endpoint needs configured handle options requests correctly—even if may set send right cors headers “normal” requests.

for details can read answer @ no 'access-control-allow-origin' header present on requested resource—when trying data rest api—but gist of is, minimally, server must respond options requests 2xx success status code.


Comments

Popular posts from this blog

Sort a complex associative array in PHP -

vb.net - How to ignore if a cell is empty nothing -

recursion - Can every recursive algorithm be improved with dynamic programming? -