Changing the json as local file causing cross domain error

Changing the json as local file causing cross domain error

j_kathiresanj_kathiresan Posts: 14Questions: 4Answers: 0

Hi,

I downloaded the plunk - http://plnkr.co/edit/OMTCvaNbjHKVjNBQrXno?p=preview and when used a local json file it throws Cross origin requests are only supported for protocol schemes: http, data, chrome, chrome-extension, https.

i have used $http.get('100.json') instead of $http.get('https://cdn.rawgit.com/angular-ui/ui-grid.info/gh-pages/data/100.json')

Please let me know how to fix it.

Thanks.

This question has an accepted answers - jump to answer

Answers

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948

    Its a security measure, see this SO thread:
    https://stackoverflow.com/questions/17947971/ajax-in-jquery-does-not-work-from-local-file

    This is outside of Datatables.

    Kevin

  • j_kathiresanj_kathiresan Posts: 14Questions: 4Answers: 0

    Hi Kevin,

    Thanks again for your kind reply. I want the same table with export options but with static data i.e json will be in the same folder where the html file is. Could you please kindly fix it or let me know what needs to be changed to make it work?

    Thanks a lot again.

  • kthorngrenkthorngren Posts: 21,310Questions: 26Answers: 4,948
    Answer ✓

    This is not a Datatables issue. The issue is trying to open a file from the local filesystem. Most web browsers won't allow this by default. You may be able to change some settings.

    The best option is to either put the file on a web server or run a web server locally and serve the file from that.

    You can google search your error and find a lot of discussions.

    Kevin

  • allanallan Posts: 63,480Questions: 1Answers: 10,467 Site admin

    Imagine if they did allow it! Wow - $.ajax( '/etc/passwd', ... )!

    There is no way a browser should allow an Ajax request to a local file.

    Allan

  • resurresur Posts: 3Questions: 1Answers: 0

    Thanks Allan and Kevin...I understand the problem...

This discussion has been closed.