php
  • javascript
  • variables
  • parameters
  • 2013-02-03 25 views 0 likes 
    0

    我有以下的javascript,從而重新加載一個PHP網站變成一個div:於JavaScript傳遞多個參數,使用PHP變量

    if (boxes.length) { 
          $(".loadingItems").fadeIn(300); 
          // Change the name here as well 
          $(".indexMain").load('indexMain.php?'+this.name+'=' + boxes.join("+"), 
          function() { 
           $(".indexMain").fadeIn('slow'); 
           $(".loadingItems").fadeOut(300); 
          }); 
    

    我想通過另一個參數在同一網址...

    所以我想我應該這樣做,如下所示,但我無法得到它的工作。這是正確的方式嗎?

    我試圖用一個PHP變量$category這樣傳遞參數categ

    if (boxes.length) { 
         $(".loadingItems").fadeIn(300); 
         // Change the name here as well 
         $(".indexMain").load('indexMain.php?categ=<?php echo $category;?>&'+this.name+'=' + boxes.join("+"), 
         function() { 
          $(".indexMain").fadeIn('slow'); 
          $(".loadingItems").fadeOut(300); 
         }); 
    
    +1

    看起來沒問題。你能顯示渲染輸出嗎? – Popnoodles

    回答

    1

    我可以看到2個這個潛在原因不能正常工作(代碼似乎罰款...):

    1. php不會執行;該javascript位於外部.js文件或該html文件具有例如.html擴展名而不是.php;
    2. 您回顯的變量包含無效字符。您應該使用urlencode以確保不會發生:<?php echo urlencode($category); ?>
    相關問題