two jquery-slider variables via ajax in php

two jquery-slider variables via ajax in php

Hello,

I have two jquery scripts. These are two range slider which creates values between 1 and 25 (level) and 1-4. (qualityId) 

I send the values of these two sliders via ajax in the php_file.php. I need the values of the sliders get changed dynamically in a link since I need to create a link to a json from where I echo out some informations via php.

So everytime a slider gets moved I want the both values gets changed dynamically and independently in a link without a page reload.

The problem

At the moment if a person moves one slider everything is working, the value in the link gets changed dynamically but if the second slider gets moved then the value from the first slider disappears. So my questions is how can I have two sliders on the page and send both values back to php.

Here are two screenshots for a better understanding. For better testing I just echo out the link on the screens.






If I change the second slider (qualityId) the values of the first slider (level) disappeears. They should be both respected. 
So in this case of the screenshots there should be the level=9 and the qualityId=4 appear in the link.

Here is the html_file.php

  1. <script>
  2. $( function() {
  3.     $( "#slider-range-max" ).slider({
  4.         range: "max",
  5.         min: 1,
  6.         max: 25,
  7.         value: 1,
  8.         stop: function(event, ui) {
  9.             $("#amount").val(ui.value);
  10.             /* Here we send the slider value towards PHP */
  11.             $.ajax({
  12.                 method: "POST",
  13.                 url: "php_file.php",
  14.                 data: { sliderVal: ui.value, sliderVal2: ui.value }
  15.             })
  16.             /* Here we receive the data back */
  17.             .done(function(data) {
  18.                 /* Here you can do whatever you want with the data */
  19.                $("#content").html(data);
  20.             });
  21.         }
  22.     });
  23.     $( "#amount" ).val( $("#slider-range-max").slider("value") );
  24. });
  25. $( function() {
  26.     $( "#slider-range-max2" ).slider({
  27.         range: "max",
  28.         min: 1,
  29.         max: 4,
  30.         value: 1,
  31.         stop: function(event, ui) {
  32.             $("#amount2").val(ui.value);
  33.             /* Here we send the slider value towards PHP */
  34.             $.ajax({
  35.                 method: "POST",
  36.                 url: "php_file.php",
  37.                 data: { sliderVal: ui.value, sliderVal2: ui.value }
  38.             })
  39.             /* Here we receive the data back */
  40.             .done(function(data2) {
  41.                 /* Here you can do whatever you want with the data */

  42.                 $("#content").html(data2);
  43.             });
  44.         }
  45.     });
  46. });

  47. </script>

  48. <input type="text" id="amount" readonly style="border:0; color:#f6931f; font-weight:bold;">
  49. <div id="slider-range-max"></div>

  50. <input type="text" id="amount2" readonly style="border:0; color:#f6931f; font-weight:bold;">
  51. <div id="slider-range-max2"></div>

  52. <div id='content'></div>

And this is my php file.php

  1. <?php 
  2. $str = $_POST['sliderVal']; 
  3. $quality = $_POST['sliderVal2']; 

  4. $str2 = file_get_contents('https://example.com/stats/258?level='. $str .'&qualityId='. $quality .'&locale=en_EN'); 

  5. $json = json_decode($str2, true); // decode the JSON into an associative array 

  6. $n= $json['health']; 
  7. echo '<div class="profile-font2">', $n, '</div>';
  8.  
  9. ?>

I think the mistake could be in the ajax- data value. I just send one value in each function, but don´t know how to fix it without destroying the both sliders.

Thanks for help.