【问题标题】:Getting Details from one Dynamic Page to Another - Re-Post从一个动态页面获取详细信息到另一个 - 重新发布
【发布时间】:2013-05-22 06:41:16
【问题描述】:

在与为 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 并且我有多个动态条目都需要这样捕获。

我正在研究这个,看来我需要以某种方式缓存这些信息......有什么想法吗?

【问题讨论】:

  • 检查我的编辑,我希望它会有所帮助:)
  • 经过 11 小时的可靠编码后,我发现我的拼写很糟糕!

标签: php jquery json variables joomla2.5


【解决方案1】:

网址传递不正确。应该是这样的:

    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();

我不确定您要发送什么值。照顾好它们(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(products) 检查 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',
                        })
            })


});

【讨论】:

  • 对不起 V.V 但如果我使用:url: "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
  • 您必须从 URL 中删除 index.php。而且我看到 produc‌​t_id... 是 HTML 元素,而不是变量。
猜你喜欢
  • 1970-01-01
  • 2016-09-03
  • 2021-10-17
  • 2013-04-12
  • 1970-01-01
  • 2022-11-27
  • 2011-07-12
  • 1970-01-01
  • 2013-01-01
相关资源
最近更新 更多