I have created a local host using python 2.0, now i'm trying to access a local file using ajax :
read.open("POST", "http://localhost:8000/text.txt", true);
read.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
read.setRequestHeader('Access-Control-Allow-Origin','*');
read.send('http://localhost:8000');
the file i'm want to access is text file
but i keep getting these error in chrome:
XMLHttpRequest cannot load http://localhost:8000/text.txt. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 501.
and these in firefox
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://localhost:8000/text.txt. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
i have looked at few answers which are
adding a extension - which is not very helpful if i'm using other browsers.
disabling security features in chrome - not a permanent solution.
Jquery plugin.
Can anyone tell me any solution that will work for JavaScript?