How can I link external json file in JSFiddle?

后端 未结 6 1454
北荒
北荒 2021-02-06 07:33
  • I have a very long .json file country.json.

[
  {
    "name": "WORLD",
    "population": 6916183000         


        
6条回答
  •  遥遥无期
    2021-02-06 08:21

    If you put the JSON file in GitHub you may also Pass response directly from GitHub Repository.

    Your JSON file must be named demo.response.json and call it as below

    /gh/get/response.json/{github_tree}/

    For instance I have that JSON file here

    https://github.com/chetabahana/chetabahana.github.io/blob/master/_data/demo.response.json

    Then in JSFiddle you can get the data using Ajax as below:

    HTML

    Result will appear below with 1 sec delay

    This text will be replaced

    JS (Choose one of Mootools Framework)

    window.addEvent('domready', function() {
        new Request.HTML({
            url: '/gh/get/response.json/chetabahana/chetabahana.github.io/tree/master/_data/',
            data: {'delay': 1},
            method: 'post',
            update: 'demo',
            onSuccess: function(response) {
                $('demo').highlight();
            }
        }).send();
    })
    

    Note: There is no JSONP functionality provided. One may achieve it using raw GitHub URL.

提交回复
热议问题