从一个动态页面获取详细信息到另一个 – 重新发布

在与JoomShopping组件编写的几乎所有代码行进行一些摔跤之后,我相信我已经找到了应该解决我所有困境的答案。

激活购物清单中的“购买”按钮后,一旦点击它,就会使用以下链接语法将产品发布到结帐购物车:

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,我有多个动态条目,所有这些都需要被捕获。

我在研究这个,似乎我需要以某种方式缓存这些信息……有什么想法吗?

url传递不正确。 它应该是这样的:

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

现在我看到你有相同名称的数组(“catid”,“quantity”……)。 你最终想要从数组中发送值吗? 因为这是另一回事。 确保“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(); 

我不确定你要发送什么值。 照顾他们(你的变量1,你的变量2 …)

现在我看到你要传递数组中的值。 试试吧

  $.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', }) }) 

此请求将仅发送第一个产品的值。 产品是一个数组,因此您可能必须通过它循环并发送多个请求才能发送所有内容。

您可以使用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', }) }) });