How to get exact value of range slider on mouse drop in jquery

+1 vote
asked Sep 13, 2017 by kalpana-devi

I just want to get the exact value of range slider on mouse drop(release).

var rangeslidervalue= $('.ex2').val(); 

I am using input type text as bootstrap slider.I have got value every time on mouse drag but i want value only on Mouse release not every time because i am hitting Ajax on when slider is drag.I have got the problem when i drag slider Ajax is hitting every time and get ERROR Failed to load resource: net::ERR_CONNECTION_TIMED_OUT Below is My slider. enter image description here

My code:

$('sliderclass').change(function() { 
  var scrollvalue = $(this).val(); 
  var dataString = JSON.stringify({ 
    scroll:scrollvalue
  }); 
  jQuery.ajax({ 
    type: "POST", 
    data: dataString,   
    contentType: "application/json; charset=utf-8", 
    url: "ajax url", 
    dataType: 'json', 
    success: function(data1) {  
      console.log(data1);
    } 
  }); 
});

thanks in advance

1 Answer

0 votes
answered Sep 13, 2017 by shoaib-zafar

usually, there is a stop callback function on slider plugin which will run when you stop dragging the element. Here is the example code of jquery ui slider for reference:

$( "#some_example_slider" ).slider({
    range: true, step: 50, min: 0, max: 450,
    values: [ 0, 450 ],
    stop: function( event, ui ) {
        var v1 = ui.values[0];
        var v2 = ui.values[1];

        $.ajax({
            type: "POST",
            url: "ajax_file.php",
            data: "value1="+v1+"&value2="+v2,
            cache: false,
            success: function(html){
                //do suff
            }
        });
    }
});
Welcome to Q&A, where you can ask questions and receive answers from other members of the community.
...