Get data from a json file via url (javascript)

Question:

I would like to know if it is possible to get the data from this json ( http://destiny.trade/JSON/sortieRewards_f.json ) without downloading it. Currently I can get the data from it, but I would like to get it through the url (when there is any update in json, get the data automatically) My code is like this: page index:

<!DOCTYPE HTML>
<html lang="pt-BR">
    <head>
        <meta charset="UTF-8">
        <title></title>
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.2.1/jquery.min.js"></script>
        <script language="JavaScript" src="https://cdn.datatables.net/1.10.13/js/jquery.dataTables.min.js" type="text/javascript"></script>
        <script language="JavaScript" src="https://cdn.datatables.net/1.10.13/js/dataTables.bootstrap.min.js" type="text/javascript"></script>
        <script language="JavaScript" src="https://cdn.datatables.net/responsive/2.1.1/js/dataTables.responsive.min.js" type="text/javascript"></script>
        <script language="JavaScript" src="https://cdn.datatables.net/responsive/2.1.1/js/responsive.bootstrap.min.js" type="text/javascript"></script>
        <script language="JavaScript" src="dados.js" type="text/javascript"></script>
        <link type="text/css" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" />
        <link type="text/css" href="https://cdn.datatables.net/1.10.13/css/dataTables.bootstrap.min.css" />
        <link type="text/css" href="https://cdn.datatables.net/responsive/2.1.1/css/responsive.bootstrap.min.css" />
    </head>
    <body>
        <div class="container">
            <div class="row">
                <div class="col-md-12">
                    <table id="example" class="table table-striped table-bordered dt-responsive nowrap" cellspacing="0" width="100%">
                        <thead>
                            <tr>
                                <th>Nome</th>
                                <th>Raridade</th>
                                <th>Drop Chance</th>
                            </tr>
                        </thead>
                    </table>
                </div>
            </div>
        </div>
    </body>
</html>

data.js page:

var data = [
    {
        "name": "Rifle Riven Mod", 
        "rarity": {
            "name": "Rare", 
            "value": "6.79%"
        }
    }, 
    {
        "name": "Ayatan Anasa Sculpture", 
        "rarity": {
            "name": "Uncommon", 
            "value": "28.00%"
        }
    }, 
    {
        "name": "4000 Endo", 
        "rarity": {
            "name": "Uncommon", 
            "value": "12.10%"
        }
    }, 
    {
        "name": "Madurai Lens", 
        "rarity": {
            "name": "Rare", 
            "value": "2.33%"
        }
    }, 
    {
        "name": "Greater Madurai Lens", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.67%"
        }
    }, 
    {
        "name": "Forma", 
        "rarity": {
            "name": "Rare", 
            "value": "2.50%"
        }
    }, 
    {
        "name": "Exilus Adapter", 
        "rarity": {
            "name": "Rare", 
            "value": "2.50%"
        }
    }, 
    {
        "name": "Orokin Reactor Blueprint", 
        "rarity": {
            "name": "Rare", 
            "value": "2.50%"
        }
    }, 
    {
        "name": "Orokin Catalyst Blueprint", 
        "rarity": {
            "name": "Rare", 
            "value": "2.50%"
        }
    }, 
    {
        "name": "Legendary Core", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.18%"
        }
    }, 
    {
        "name": "Vazarin Lens", 
        "rarity": {
            "name": "Rare", 
            "value": "2.33%"
        }
    }, 
    {
        "name": "Zenurik Lens", 
        "rarity": {
            "name": "Rare", 
            "value": "2.33%"
        }
    }, 
    {
        "name": "Naramon Lens", 
        "rarity": {
            "name": "Rare", 
            "value": "2.33%"
        }
    }, 
    {
        "name": "Unairu Lens", 
        "rarity": {
            "name": "Rare", 
            "value": "2.33%"
        }
    }, 
    {
        "name": "Greater Vazarin Lens", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.67%"
        }
    }, 
    {
        "name": "Greater Zenurik Lens", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.67%"
        }
    }, 
    {
        "name": "Greater Naramon Lens", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.67%"
        }
    }, 
    {
        "name": "Greater Unairu Lens", 
        "rarity": {
            "name": "Legendary", 
            "value": "0.67%"
        }
    }, 
    {
        "name": "Credit Booster", 
        "rarity": {
            "name": "Rare", 
            "value": "3.27%"
        }
    }, 
    {
        "name": "Affinity Booster", 
        "rarity": {
            "name": "Rare", 
            "value": "3.27%"
        }
    }, 
    {
        "name": "Resource Drop Chance Booster", 
        "rarity": {
            "name": "Rare", 
            "value": "3.27%"
        }
    }, 
    {
        "name": "Pistol Riven Mod", 
        "rarity": {
            "name": "Rare", 
            "value": "7.61%"
        }
    }, 
    {
        "name": "Shotgun Riven Mod", 
        "rarity": {
            "name": "Ultra Rare", 
            "value": "1.36%"
        }
    }, 
    {
        "name": "Melee Riven Mod", 
        "rarity": {
            "name": "Rare", 
            "value": "9.14%"
        }
    }
];

    $(document).ready(function () {
        $('#example').DataTable({
            "processing": true,
            "info": true,
            "stateSave": true,
            data: data,
            "columns": [
                { "data": "name" },
                { "data": "rarity.name"},
                { "data": "rarity.value"}
            ]
        });
    });

Answer:

As you already use jQuery you can use a function that is jQuery.getJson()

Example:

$.getJSON(url, function(result){
  // result é o json obtido
});

Practice:

$.getJSON("http://destiny.trade/JSON/sortieRewards_f.json", function(result){
  // result, é o seu "data"
});
Scroll to Top
AllEscort