2013-05-22 50 views
1

經過與爲JoomShopping組件編寫的幾乎每一行代碼的一些摔角之後,我相信我已經找到了應該解決所有困境的答案。從一個動態頁面到另一個頁面獲取詳細信息 - 重新發布

當購物清單激活「購買」按鈕,一次就可以點擊使用下面的鏈接語法,以便將產品發佈到Google Checkout購物車:

index.php/cart/add?category_id=2&product_id=12&quantity=4 

其中2爲類別ID和12是產品ID等等...這是由V.Vachev解決,但我認爲審慎的做法後所有的成品/固定OCED,因爲它的工作原理:

$('.checkOut').live('click',function(){ 
    var products= new Array(); 
$(".jshop_prod_cart").each(function(){ 
    var product = new Object(); 
     product.catid = $(this).find('[name="category_id"]').val(); 
      product.id = $(this).find('input[name="product_id"]').val(); 
      product.qanty = $(this).find('input[name^="quantity"]').val(); 
    products.push(product) 
    $.ajax({ 
        type: 'GET', 
       url: "shop-portal/add?category_id="+products[0].catid+"&product_id="+products[0].id+"&quantity="+products[0].qanty, 
        dataType: 'json', 
        }) 

     }) 
    }) 

這將返回:

http://www.domain.com/index.php/shop-portal/add?category_id=2&product_id=48&quantity=4

但它只返回1和I具有多個動態條目所有需要被捕捉爲這樣。

我正在研究這個,似乎我需要緩存這個信息莫名其妙...任何想法?

+0

檢查我的編輯,我希望這將有助於:) –

+0

我有,我發現,這是我的拼寫是11小時實編碼後attrocious! – user2265402

回答

0

URL傳遞不正確。它應該是這樣的:

url: "/shop-portal/add?category_id="+catid+"&product_id="+id+"&quantity="+qanty, 

現在我看到你有相同的名稱(「catid」,「數量」...)的數組。你最終想發送數組中的值嗎?因爲這是另一回事。確保「catid」,「id」和「qanty」是全局變量,併發送所需的值。

Joomla是大概沒想到JSON數據,嘗試用原生Ajax請求

var xmlhttp; 
if (window.XMLHttpRequest) 
    { 
    xmlhttp=new XMLHttpRequest(); 
    } 
else 
    { 
    xmlhttp=new ActiveXObject("Microsoft.XMLHTTP"); 
    } 
xmlhttp.onreadystatechange=function() 
    { 
    if (xmlhttp.readyState==4 && xmlhttp.status==200) 
    { 
    alert("Sent!"); 
    } 
    } 
xmlhttp.open("GET","/shop-portal/add?category_id="+yourvariable+"&product_id="+yourvariable+"&quantity="+yourvariable); 
xmlhttp.send(); 

我不知道要送什麼值。照顧他們(yourvariable1,yourvariable2 ...)

現在我看到你想傳遞數組中的值。試用

$.ajax({ 
    type: 'GET', 
    data:products, 
    url: "/shop-portal/add?category_id="+products[0].catid+"&product_id="+products[0].id+"&quantity="+products[0].qanty, 
    dataType: 'json', 
    }) 
}) 

該請求將僅發送第一個產品的值。 Products是一個數組,因此您可能必須循環併發送多個請求才能發送所有內容。

您可以使用console.log(產品)檢查var「products」包含的內容。這將在控制檯(例如Firebug)中顯示內容。

$('.checkOut').live('click',function(){ 
var products= new Array(); 
     $(".jshop_prod_cart").each(function(){ 
      var product = new Object(); 
     product.catid = $(this).find('[name="category_id"]').val(); 
     product.id = $(this).find('input[name="product_id"]').val(); 
     product.qanty = $(this).find('input[name^="quantity"]').val(); 
     products.push(product) 


         $.ajax({ 
         type: 'GET', 
         data:products, 
         url: "/shop-portal/add?category_id="+product.catid+"&product_id="+product.id+"&quantity="+product.qanty, 
         dataType: 'json', 
         }) 
      }) 


}); 
+0

抱歉,如果我使用: 'url:\t「index.php/shop-portal/add?category_id =」+ category_id +「&product_id =」+ product_id +「&quantity =」+ quantity,' 我們得到:'http: //cardoso.co.za/index.php/index.php/shop-portal/add?category_id= [object%20HTMLInputElement]&product_id = [object%20HTMLInputElement]&quantity = [object%20HTMLInputElement]&undefined = undefined' – user2265402

+0

您必須從URL中刪除index.php。我看到produc t_id ...是HTML元素,而不是變量。 –

相關問題