1

I'm trying to set up a website to run on the local file system and call an XML file, but I'm getting access control origin errors:

Origin null is not allowed by Access-Control-Allow-Origin.

I've tried switching the datatype to jsonp and setting crossdomain to true:

$j.ajax({
            crossdomain: true,
            url: 'xml/vehicles.xml',
            dataType: "jsonp",      
            success: function( vehicleXML ) {
                supertree.parseVehicles($j(vehicleXML).find("vehicles"), null);
                supertree.vehiclesLoaded = true;
                if(supertree.scenesLoaded) supertree.ready();
            }
        }); 

But it doesn't work. Any idea on how to accomplish this? Preferably without a proxy?

1
  • Since you are working from the filesystem, there are a whole new list of restrictions and cross-browser differences. For example, Chrome won't allow you to perform any XMLHTTP request to the filesystem unless you run chrome with the correct flag. Other browsers may allow the request without issue. Changing to JSONP instead of XML will be the most cross-browser way to handle it. Commented Apr 24, 2012 at 15:41

1 Answer 1

2

Same origin policy prevents you have accessing the data. Either the server you are requesting data from needs to enable CORS or you need to use a proxy on your server to get the data from the other server.

Other option is to change the XML data into a JSONP format. It is not as easy as telling jQuery to make a JSONP request. The data formats are totally different and the server has to return that format, the JavaScript cannot do anything about it.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.