Go Back   CodingForums.com > :: Client side development > JavaScript programming > JavaScript frameworks

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-15-2012, 01:44 PM   PM User | #1
denhamd2
New Coder

 
Join Date: Sep 2004
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
denhamd2 is an unknown quantity at this point
Problem with jquery & AJAX GET

Hi,

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.

Code:
var dlink1 = $('a.addlink1').attr('href'); 
var dlink2 = $('a.addlink2').attr('href'); 
var dlink3 = $('a.addlink2').attr('href'); 


$('a.submitbutton').click(function() {

    $.ajax({
            type: 'GET',
            beforeSend: function() {

if(dlink1 != '') { $.get(dlink1) }
if(dlink2 != '') { $.get(dlink2) }
if(dlink3 != '') { $.get(dlink3) }

            },
           success: function() {
window.location = '/cart.php';      
      }
        });


    return false;
});
denhamd2 is offline   Reply With Quote
Old 12-15-2012, 02:12 PM   PM User | #2
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Code:
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:
Code:
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
AndrewGSW is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 06:11 AM.


Advertisement
Log in to turn off these ads.