How can I get javascript to read from a .json file?

前端 未结 5 1749
-上瘾入骨i
-上瘾入骨i 2020-12-01 00:48

My script currently looks like this:



        
5条回答
  •  一整个雨季
    2020-12-01 01:32

    Assuming you mean "file on a local filesystem" when you say .json file.

    You'll need to save the json data formatted as jsonp, and use a file:// url to access it.

    Your HTML will look like this:

    
    
    

    And the file c:\data\activity.jsonp contains the following line:

    jsonstr = [ {"date":"July 4th", "event":"Independence Day"} ];
    

提交回复
热议问题