2014-03-31 30 views
0

我有兩個文件filter.php和products.php包含在index.php中,我正在使用.post提交表單而不刷新。我將數據發送到products.php並將其返還,同時我刷新了過濾器,這是我的問題。當我嘗試變種轉儲後數據filter.php是空如何使用ajax獲取帖子值.post

這裏是我的腳本

function ajaxFilter() 
{ 
     var str = jQuery("form[name=\"filters\"]").serialize(); 
     jQuery.post("/", str) 
      .done(function(data) { 
      var productList = jQuery(data).find(".list_product").html(); 
      var filter = jQuery(data).find(".filters").html(); 
      jQuery(".list_product").html(productList); 
      jQuery(".filters").html(filter); 
     });  
} 

任何想法如何讓POST?

不過,我覺得這會讓我的文章通過腳本來隱藏輸入,也回報他們以HTML

如果是壞主意或絕對錯誤的開始。

+0

@ICanHasCheezburger? – Neel

+0

@Neel o_O?..... –

回答

0

試試這個:

 var Data = $("form[name=\"filters\"]").serializeArray(); 
     var URL = "products.php"; // whatever filepath where you send data 
     jQuery.ajax({ 
      type: "POST", 
      url: URL, 
      processData: true, 
      data: Data, 
      dataType: "html", 
      success: function (productList) { 
        // filter your result whatever you return from products.php 
       jQuery(".list_product").html(productList); 
      }, 
      error: function (x, y, z) { 
       var a = x.responseText; 
       jQuery(".list_product").html(a); 
      } 
     }); 
+0

不完全是我尋找的,但它幫助我找到另一個解決方案thx;) – user2826311

0

使用完整的URL。

如果仍有問題,請提供.error()的返回值。