Hello and welcome to our community! Is this your first visit?
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    Sep 2004
    Thanked 0 Times in 0 Posts

    Problem with jquery & AJAX GET


    I'm using jquery to make an Ajax GET call. Basically on my page I have 3 buttons to add products. What I want is for all 3 to be added to my shopping cart page at once. It works fine when I don't have a redirect and go to the cart page manually. The problem is when I add the redirect code, it only adds the first product. Any help on this problem would be much appreciated.

    var dlink1 = $('a.addlink1').attr('href'); 
    var dlink2 = $('a.addlink2').attr('href'); 
    var dlink3 = $('a.addlink2').attr('href'); 
    $('a.submitbutton').click(function() {
                type: 'GET',
                beforeSend: function() {
    if(dlink1 != '') { $.get(dlink1) }
    if(dlink2 != '') { $.get(dlink2) }
    if(dlink3 != '') { $.get(dlink3) }
               success: function() {
    window.location = '/cart.php';      
        return false;

  2. #2
    Senior Coder
    Join Date
    Apr 2011
    London, England
    Thanked 354 Times in 353 Posts
    var dlink1 = $('a.addlink1').attr('href'); 
    var dlink2 = $('a.addlink2').attr('href'); 
    var dlink3 = $('a.addlink2').attr('href'); // is this correct..?
    I would question why you are using classes, rather than ids, for what appear to be specific elements; particularly for 'submitbutton' - I assume there is only one.

    But, as far as a little digging tells me, the get() method is not used to add parameters to a url - unless I've missed something(?). You need to append these values manually using encodeURIComponent:
    window.location = '/cart.php?' + encodeURIComponent(somegets);
    "I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
    Validate your HTML and CSS


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts