i want to open a local file by Patch in javascript client-side . this is my code below -im using xmlhttprequest method :
<script type='text/javascript'>
function readfilebypatch(file)
{
var rawfile = new XMLHttpRequest();
rawfile.open("GET" , file , true);
var all ;
alert("in");
rawfile.onreadystatechange = function ()
{
if ( rawfile.status === 200 || rawfile.status == 0)
{
all = rawfile.responseText;
alert(all);
}
}
//rawfile.send('0');
}
readfilebypatch("file:///c:/users/acer/desktop/tavasoli.txt");
</script>
so i got this error after in alert :
ccess to XMLHttpRequest at 'file:///C:/users/acer/desktop/tavasoli.txt' from origin 'null' has been blocked by CORS policy: Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.
andthis warning :
[Violation] 'readystatechange' handler took 1241ms
and this one :
BASE64.HTML:32 GET file:///C:/users/acer/desktop/tavasoli.txt net::ERR_FAILED
so i know my browser ( chrome ) is blocking these kind of requests and i have to do this : https://www.chrome-allow-file-access-from-file.com/windows.html but this doesnt work . Note: is there other way to open file in javascript client side ? thanks!