Getting Details from one Dynamic Page to Another - Re-Post

懵懂的女人 提交于 2020-01-05 10:27:18

问题


After some wrestling with almost every line of code written for the JoomShopping component I beleive I have found what should be the answer to all my woes.

When activating the "Buy" button in the shopping list and once clicked on it uses the following link syntax in order to post a Product to the Checkout Cart:

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

Where 2 is the Category ID and 12 is the Product ID etc ... This was solved by V.Vachev, but I thought it prudent to post all of the finished/fixed oced as it works:

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

        })
    })

this returns:

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

BUT it is only returning the 1 and I have multiple dynamic entries which all need to be captured as such.

I am researching this, it seems I need to cache this information somehow ... Any ideas?


回答1:


URL passing wasn't correct. It should be like that:

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

Now I see that you have array with the same names ("catid", "quantity" ...). Do you eventually want to send the values from the array? Because this is another thing. Make sure that "catid", "id" and "qanty" are global variables and you send the desired values.

Joomla is probably not expecting JSON data, try with native ajax request

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

I'm not sure what values you want to send. Take care of them (yourvariable1, yourvariable2...)

Now I see that you want to pass values from the array. Try with

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

This request will send only the values from the first product. Products is an array so you probably must loop thru it and send multiple requests in order to send everything.

You can check what does the var "products" contain with console.log(products) .This will display the content in the console (Firebug for example).

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


});


来源:https://stackoverflow.com/questions/16685070/getting-details-from-one-dynamic-page-to-another-re-post

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!