2017-08-15 35 views
0

我需要能夠從我的PHP腳本發送一個值,名爲$ topid的變量需要將該id發送到getData.php腳本,所以我嘗試了像如何通過post添加一個新變量到這個ajax腳本

$(document).ready(function(){ 

    // Load more data 
    $('.load-more').click(function(){ 
     var topid = Number($('#topid').val()); 
     var row = Number($('#row').val()); 
     var allcount = Number($('#all').val()); 
     row = row + 3; 

     if(row <= allcount){ 
      $("#row").val(row); 

      $.ajax({ 
       url: 'getData.php', 
       type: 'post', 
       data: {row:row}, 
       beforeSend:function(){ 
        $(".load-more").text("Loading..."); 
       }, 
       success: function(response){ 

        // Setting little delay while displaying new content 
        setTimeout(function() { 
         // appending posts after last post with class="post" 
         $(".post:last").after(response).show().fadeIn("slow"); 

         var rowno = row + 3; 

         // checking row value is greater than allcount or not 
         if(rowno > allcount){ 

          // Change the text and background 
          $('.load-more').text("Hide"); 
          $('.load-more').css("background","darkorchid"); 
         }else{ 
          $(".load-more").text("Load more"); 
         } 
        }, 2000); 


      } 
     }); 
    }else{ 
     $('.load-more').text("Loading..."); 

     // Setting little delay while removing contents 
     setTimeout(function() { 

      // When row is greater than allcount then remove all class='post' element after 3 element 
      $('.post:nth-child(3)').nextAll('.post').remove().fadeIn("slow"); 

      // Reset the value of row 
      $("#row").val(0); 

      // Change the text and background 
      $('.load-more').text("Load more"); 
      $('.load-more').css("background","#15a9ce"); 

     }, 2000); 


    } 

}); 

});

但不知怎的,它似乎並沒有工作,我需要的是id發送到getData.php腳本,然後通過後像$ topid = $ _POST ['topid'];

回答

0

如果需要發送topidgetData變化

data: {row:row} 

成類似

data: {topid : topid} 
+0

我沒有說太多,但後來我試圖呼應它正在傳遞沒有值 –

相關問題