How to turn to the json field



  • Good afternoon. Just started studying js. There's another problem. I'm reading json files and I'm fine. I'm checking the aterto-- it's stretched:

    $(function () {
        $.getJSON("/skiresort/forslider", function( data ) { 
            var items = [];
    
        $.each(data, function( key, val ) {
            alert(data.max_total_km_of_tails);
        });
    });
    

    });

    Next, I need to use this value in the slider, but in response, I get a mistake Uncaught ReferenceError: data is not defined with an error in the call line:

    $(function () {
    var slider = $("#skilable").slider({
    range: "min",
    value: 0,
    min: 0,
    max: data.max_total_km_of_tails,
    step: 1
    });
    });

    Please tell me what I'm doing wrong.



  • Looks like it should be like,

    $(function () {
        $.getJSON("/skiresort/forslider", function( data ) { 
            var slider = $("#skilable").slider({
                range: "min",
                value: 0,
                min: 0,
                max: data.max_total_km_of_tails,
                step: 1
            });
        });
    });
    

Log in to reply
 


Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2