0

I am trying to embed log file in a jsp page, for that I have tried and in both cases its not embeding. When i searched in SO, i found a link doing with jquery. but its also not working, it displayed the following message on console : Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https. the below is my code:

<div id="myLogFile">
</div>

<script>
$(document).ready(function() {
    $.ajax({
        async:false,
        url: 'C:\Users\Documents\cmesLoading\spring_app_log_file.log',
        dataType: 'text',
        success: function(data) 
        {
        $('#myLogFile').append(data);
            }
        });
});

</script>

Can someone help me on this?

ASR
  • 3,289
  • 3
  • 37
  • 65

2 Answers2

1

This code will run on your server because CORS on browsers don't allow local files to be loaded. If you have a web server (Apache, Nginx, IIS, etc) you can test it on the server with using relative or http(s) schemed URL, and see it working.

And a website showing how to bypass it on some browsers:

https://www.thepolyglotdeveloper.com/2014/08/bypass-cors-errors-testing-apis-locally/

Some excerpt from it:

For Google Chrome run:

Chrome.exe --disable-web-security

For Firefox in about:config disable (may be for old version):

security.fileuri.strict_origin_policy

etc.

Keywords: "enable cors on local files"

Taha Paksu
  • 15,371
  • 2
  • 44
  • 78
1

UR url is wrong u r providing the url which is referring to ur local hard drive. No u have to put ur log file into the server's public folder and request that file from server then only u will be able to get the data from file.

<div id="myLogFile">
</div>

<script>
$(document).ready(function() {
    $.ajax({
        async:false,
        url: 'http://your-domain.com/cmesLoading/spring_app_log_file.log',
        dataType: 'text',
        success: function(data) 
        {
        $('#myLogFile').append(data);
            }
        });
});

</script>
RK_15
  • 929
  • 5
  • 11