JQuery.getJSON() reading a local file

前端 未结 4 625
情话喂你
情话喂你 2020-12-11 18:30

How do you read a file in the current directory using JQuery.getJSON()?

I\'m trying something simple (with my data.json file in the same directory as my html file):<

4条回答
  •  南笙
    南笙 (楼主)
    2020-12-11 19:03

    An alternative to installing a local LAMP server is to use python's simple HTTP server. As long as you have python installed, just open up bash and use the python interpreter.

    For python 2 use:

    python -m SimpleHTTPServer 8000
    

    For python 3 use:

    python -m http.server 8000
    

    Then just point your browser at localhost:8000 and you shouldn't have any trouble accessing the file if it's in the same directory.

提交回复
热议问题