0

I have a jquery function which looks like

<script type="text/javascript">
var doubleEliminationData = {}
$(function () {
    $('div#doubleElimination').bracket({
        init: doubleEliminationData
    })
})  
</script>

and the content of the variable doubleEliminationData is in a JSON file. When i copy/paste the code in the JSON file in the variable it works just fine. But i need to load it from the JSON file because on an other website i can change the content in this file. I tried $.get, $.getjson and $.ajax to get the content of the file but it doesnt work. I hope you can help withe this. How do i load the content of the JSON file into the var doubleEliminationData?

palaѕн
  • 72,112
  • 17
  • 116
  • 136

1 Answers1

0

You can try to do this with Ajax:

$.ajax({
    dataType: "json",
    url: urlPathToYourFile,
    data: data,
    success: successFn
});

or you can use shorthand Ajax function jQuery.getJson()

$.getJSON("yourJsonFile.json", function(data) {
    console.log(data);//output your data to console
});
merezha
  • 73
  • 6
  • hi. the $.getJSON worked just fine. I also had to request the json file from the main domain and not the subdomain. Is it possible to do this request in a function? When I try to put it in a function, the request is not send. Any idea? – user2963692 Nov 07 '13 at 19:02