Dad72 Posted November 4, 2015 Share Posted November 4, 2015 Hello, I am looking to importMesh() from my server (http://www.castorengine.com) on my local project (http://1270.0.1:122). but each time I : No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://127.0.0.1:122' is therefore not allowed access. I added on every page: header('Access-Control-Allow-Origin: *');I did like this: By http://www.castorengine.comfunction Importer(url, type) { parent.postMessage({url:url, type:type}, '*');}To http://127.0.0.1:122window.addEventListener('message', function(event) { if (~event.origin.indexOf('http://www.castorengine.com')) { var data = event.data; layout.addObjet.importMediaStore(data.url, data.type); }});Why I have this error Access-Control-Allow-Origin and how to solve it. with this url : http://www.castorengine.com/boutique/MESHES/table/table.babylon Thanks for help Quote Link to comment Share on other sites More sharing options...
JCPalmer Posted November 4, 2015 Share Posted November 4, 2015 I have been in this area today too. Looking at Tools.LoadImage(), it can set a img.crossOrigin. You are probably calling Tools.LoadFile() sooner or later. That is a XMLHttpRequest. Do not know if that has something similar. My usage was getting .asf & .amc files for Mocap conversion to animations. For dev, I downloaded a 1 GB zip file, expanded it, & put html & js files in root of expansion dir. doing a relative GET works as long as I start by double clicking html file. I am just do it for myself, but this is not practical for sharing. Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 4, 2015 Author Share Posted November 4, 2015 I also this error just before: Cannot read property '_addPendingData' of undefined and after: Uncaught Error: Error status: 0 - Unable to load http/.... Here is the URL that uses : http://www.castoreng...e/table.babylon BABYLON.SceneLoader.ImportMesh("", "http://www.castorengine.com/boutique/MESHES/table/", "table.babylon", scene, function (newmeshes, particleSystems, skeletons) {This would be due to load images that turn around this error? There was not a fix that can be done to Babylon for this ? Quote Link to comment Share on other sites More sharing options...
davrous Posted November 4, 2015 Share Posted November 4, 2015 We can't do nothing on the Babylon.js side. This is pure web constraints. CORS rules is part of the web. You need to setup CORS on your web server to allow specific domains (or anybody with *) to access your resources using XHR. Search on the web on how to setup anonymous CORS on your webserver based on what you're currently using (Apache or IIS? PHP? etc.). We've setup CORS rules on our CDN for babylonjs.com. No other choice. David Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 4, 2015 Author Share Posted November 4, 2015 Davrous thank you. you will not have a link that would help me. I try this:<?phpheader('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET,PUT,POST,OPTIONS');header("Access-Control-Allow-Headers: X-Requested-With");?>not work. I try this: .htaccess<IfModule mod_headers.c> Header set Access-Control-Allow-Origin * Header set Access-Control-Allow-Credentials true</IfModule>I have no idea Quote Link to comment Share on other sites More sharing options...
jerome Posted November 4, 2015 Share Posted November 4, 2015 I guess the header must be sent by the Origin 127.0.0.1, your local webserverThe SOP (same origin policy) prevents your browser to request with xhr other domains than the one from where your html page was downloaded (the Origin)... unless the Origin domain tells it allows its html page to request other domains than itself Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 4, 2015 Author Share Posted November 4, 2015 The SOP (same origin policy) prevents your browser to request with xhr other domains than the one from where your html page was downloaded (the Origin)... unless the Origin domain tells it allows its html page to request other domains than itself This is what I normally did here:<?phpheader('Access-Control-Allow-Origin: *');header('Access-Control-Allow-Methods: GET,PUT,POST,OPTIONS');header("Access-Control-Allow-Headers: X-Requested-With");?>This is added from the local page and the same is on the call page. But do not work. Ce qui est étrange c’est que ca fonctionne si j'envoie du texte par exemple, je le reçois bien, donc mon Access-Control-Allow-Origin est ok. c’est le imporMesh qui ne fonctionne pas avec l'url reçue (que je reçois). l'erreur ne viendrais pas de ici : BABYLON.SceneLoader.ImportMesh("", "http://www.castorengine.com/boutique/MESHES/table/", "table.babylon", scene, function (newmeshes) Quote Link to comment Share on other sites More sharing options...
Dad72 Posted November 6, 2015 Author Share Posted November 6, 2015 Ok, it works now. Solution: on SSH comande: apachectl -tapachectl -k gracefulsudo service apache2 reloada2enmod headers .htaccess on the serveur call (SSH commands beings must do to avoid the error 500)Header set Access-Control-Allow-Origin "*"Header set Access-Control-Allow-Headers "Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With" Header set Access-Control-Allow-Methods "PUT, GET, POST, OPTIONS"and page .php call<?php$origin=isset($_SERVER['HTTP_ORIGIN'])?$_SERVER['HTTP_ORIGIN']:$_SERVER['HTTP_HOST'];header('Access-Control-Allow-Origin: '.$origin); header('Access-Control-Allow-Methods: POST, OPTIONS, GET, PUT');header('Access-Control-Allow-Credentials: true');header('Access-Control-Allow-Headers: Cache-Control, Pragma, Origin, Authorization, Content-Type, X-Requested-With');header('P3P: CP="NON DSP LAW CUR ADM DEV TAI PSA PSD HIS OUR DEL IND UNI PUR COM NAV INT DEM CNT STA POL HEA PRE LOC IVD SAM IVA OTC"');header('Access-Control-Max-Age: 1');?>And finaly: Empty cache browser. Work for FireFox and Chrome. Quote Link to comment Share on other sites More sharing options...
GameMonetize Posted November 6, 2015 Share Posted November 6, 2015 Well done! You are resilient! I like that Dad72 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.