2017-10-09 91 views
-1

我已經在我的HTML文件如下:傳遞一個HTML變量到PHP文件

<div class="panel-body panel-refine"> 
<span id="price-left" class="price-left pull-left" data-currency="&euro;">500</span> 
<span id="price-right" class="price-right pull-right" data-currency="&euro;">5000</span> 
<div class="clearfix"></div> 

變量price-left和「價格正確」來自一個JavaScript滑塊。

$(document).ready(function(){ 

     var slider2 = document.getElementById('sliderRefine'); 

     noUiSlider.create(slider2, { 
      start: [2000, 3000], 
      connect: true, 
      range: { 
       'min': [30], 
       'max': [5000] 
      } 
     }); 

     var limitFieldMin = document.getElementById('price-left'); 
     var limitFieldMax = document.getElementById('price-right'); 
    var xhr; 
    slider2.noUiSlider.on('update', function(values, handle){ 
     if (handle){ 
       limitFieldMax.innerHTML= $('#price-right').data('currency') + Math.round(values[handle]); 
       document.getElementById("hoogsteprijs").innerHTML = Math.round(values[handle]); 
     } else { 
       limitFieldMin.innerHTML= $('#price-left').data('currency') + Math.round(values[handle]); 
       document.getElementById("laagsteprijs").innerHTML = Math.round(values[handle]); 
     } 

     // Abort the previous asynchronous ajax call in case it hasn't finished loading 
     if(xhr && xhr.readyState != 4){ 
      xhr.abort(); 
     } 

     xhr = $.ajax({ 
      url: 'search.php', 
      type: 'GET', 
      data:{ 
       minPrice: document.getElementById("laagsteprijs").innerHTML, 
       maxPrice: document.getElementById("hoogsteprijs").innerHTML 
      }, 
      success:function(response){ 
       // do something with response from search.php 

      } 
     }); 
     }); 
    }); 

我想通過 「laagsteprijs」 和 「hoogsteprijs」 與我在一個HTML文件中調用與如下因素的search.php一個文件:

<iframe width="100%" height="720" src="search.php?q=category%3AFietsen&page=1&sort=priceAsc&minPrice="laagsteprijs"&maxPrice="hoogsteprijs"" style="border:none;"></iframe>

+2

的可能的複製[?如何JavaScript的變量傳遞給PHP(https://stackoverflow.com/questions/1917576/how-to-通javasc ript-variables-to-php) –

+2

您必須將JavaScript變量'$ _POST'改爲PHP。此外,StackOverflow不是一個免費的代碼寫入服務,並期望您[**嘗試首先解決您自己的問題**](http://meta.stackoverflow.com/questions/261592)。請更新您的問題以顯示您已經嘗試過的內容,展示** [**最小,完整和可驗證示例**]中面臨的**特定**問題(http://stackoverflow.com/help/mcve )。有關詳細信息,請參閱[**如何提出良好問題**](http://stackoverflow.com/help/how-to-ask),並參加[**網站**之旅](http ://stackoverflow.com/tour)。 –

回答

0

使用jQuery $就功能將數據傳遞到您的search.php腳本每個滑塊更新:

var xhr; 
slider2.noUiSlider.on('update', function(values, handle){ 
    if (handle){ 
      limitFieldMax.innerHTML= $('#price-right').data('currency') + Math.round(values[handle]); 
      document.getElementById("hoogsteprijs").innerHTML = Math.round(values[handle]); 
    } else { 
      limitFieldMin.innerHTML= $('#price-left').data('currency') + Math.round(values[handle]); 
      document.getElementById("laagsteprijs").innerHTML = Math.round(values[handle]); 
    } 

    // Abort the previous asynchronous ajax call in case it hasn't finished loading 
    if(xhr && xhr.readyState != 4){ 
     xhr.abort(); 
    } 

    xhr = $.ajax({ 
     url: 'search.php', 
     type: 'GET', 
     data:{ 
      minPrice: document.getElementById("laagsteprijs").innerHTML, 
      maxPrice: document.getElementById("hoogsteprijs").innerHTML 
     }, 
     success:function(response){ 
      // do something with response from search.php 
     } 
    }); 


}); 
+0

謝謝你的回覆。我將在本週嘗試。我會讓你知道結果。克。吉姆 –

+0

謝謝你的回覆。根據你的回答,我改變了我的問題。我現在不會如何回答。這似乎是最明顯的解決方案。克。 Jim –

+0

[link](https://jimmeijer-test.nl/openfiets) –