在单击之前为按钮分配链接

时间:2013-05-22 14:19:48

标签: php jquery ajax joomla

在我previous question我请求帮助改进特定语法的URL输出时,我现在设法做到了这一点,但只针对一个实例。

我研究过的是我应该使用缓存来存储这些多个URL值,然后在时机成熟时提交所有这些值?

如果你将鼠标放在"购买"在许多产品之一上的按钮,您将看到具有以下语法的URL /链接:

add?category_id=2&product_id=# 

Value parsed between product and checkout

我已在My Dynamic Cart System(红色部分)中复制了此行为,但它只会在onclick上推送该URL。有没有办法在点击之前将它分配给我的提交按钮?

在此功能中创建并调用URL:

$('.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: 'POST',
            //data:products,
            //dataType: 'json',
            url: "shop-portal/add?category_id="+products[0].catid+"&product_id="+products[0].id+"&quantity="+products[0].qanty
        });
    });
});

除非有办法强制进入URL地址栏,因为它似乎根本没有到达那里,它只是在后台运行......(我认为)

还有" Controller"此扩展程序中的许多内容查询的文件。怎么样?我真的不知道......如果有人试图修改或自定义Joomshopping的后端脚本,请帮忙!

1 个答案:

答案 0 :(得分:0)

您可以在页面加载时执行此操作,例如:

var products= [];
$(document).ready(function() {
    $(".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);
    });
});

点击

$(document).on('click', '.checkOut' ,function(){
  //your ajax code here
});

已添加,您可以使用jQuery.on()以防万一您的网址动态加载,例如:

$(document).on('click', '.checkOut',function(){
   //your code here
});