Thursday 15 January 2015

javascript - Obtain data from JSon after choosing a field with a JQuery UI slider -


I am doing a webpage which has a jeiIIi UI slider where you can choose one year. After the stop event of the slider, I want the webpage to show data from a JSON file related to the year I was selected. First of all, I would like to know what is possible with this dimension (I am using HTML + CSS + Javascript).

And second, here is the stop event of the slider:

  stop: function (event, UI) {warning ('off' + ui.value); $ .getJSON ('winners.jason', function (winner) {var output = ""; output + = winners.drive [ui.value] .name; document.getElementById ("winner"). InnerHTML = output;}) ; }   

The warning slider displays the selected year correctly.

2 fields of winners.json (year, name), the driver is the name of the JSon Array and the winner is a placeholder in the HTML

winners.json of your description, it seems that you have an object named driver that contains an array array Each of the objects has two fields: year and names . Then, you are trying to reach the name area such as the year inside the field ... it was being processed ... year > field If this is the case, you need to reconstruct your winners.json file to match your code, or is easy ... name correctly. / P>

If they are siblings, then you can do something like this:

 for  (var i = 0, len = winners.driver.length; i & lt ; Len; i ++) {If (winners.driver [i] .year === ui.value) {output = winners.d driver [i] .name; }}   

Also, make sure that the winners.json file has been uploaded to your web server, and when you make your call, Are referred to. Depending on what you have, it will see your HTML file in the same directory which is calling.

No comments:

Post a Comment