1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

[???] Adding two or more numbers generated by .js pages ...

Discussion in 'HTML & JavaScript' started by OTrap, Dec 29, 2013.

  1. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    I was picking through some GetResponse scripting, and I came across links like this:

    https://app.getresponse.com/display_subscribers_count.js?campaign_name=[CAMPAIGN_NAME]&var=0

    They return the number of subscribers in that campaign.

    My question is, can these numbers be added up using Javascript to give one total?

    Two examples of URLs that give such numbers (if anyone wishes to test) are:

    https://app.getresponse.com/display_subscribers_count.js?campaign_name=lzlitki&var=0
    https://app.getresponse.com/display_subscribers_count.js?campaign_name=admin_682519&var=0


    Thanks in advance!
     
  2. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    try this
    http://jsfiddle.net/8J2E4/
    Code:
    var count = 0;
    var camp = ['lzlitki','admin_682519'];
    var idx = 0;
    
    function next() {
        if ( idx == camp.length ) {
            alert('total '+count);
            return;
        }
        $.ajax({
             url:'https://app.getresponse.com/display_subscribers_count.js?campaign_name='+camp[idx++]+'&var=0',
             dataType: 'jsonp',
             success:function(json){
                 count += json.counter;
                 next();
             },
             error:function(){
                 alert('Error');
             },
        });
    }
    next();
    
     
    • Thanks Thanks x 1
  3. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    Thanks for the reply.

    I was placing this code on an HTML page (in script tags), and it wasn't doing anything, but I see it working on the page you showed here.

    Not sure why it isn't working on my own page.
     
  4. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    Perhaps I don't have the tags correct or something. I'm relatively new to messing with Javascript.

    Here's what I have, per the last reply:

    Code:
    <!DOCTYPE HTML>
    <html>
    <head>
    <title>Total GR Subscribers</title>
    </head>
    <body><script>
    var count = 0;
    var camp = ['lzlitki','admin_682519'];
    var idx = 0;
    
    function next() {
        if ( idx == camp.length ) {
            alert('total '+count);
            return;
        }
        $.ajax({
             url:'https://app.getresponse.com/display_subscribers_count.js?campaign_name='+camp[idx++]+'&var=0',
             dataType: 'jsonp',
             success:function(json){
                 count += json.counter;
                 next();
             },
             error:function(){
                 alert('Error');
             },
        });
    }
    next();
    </script>

    Here's how it's showing up:
    http://6fig.co/m/bigtest/test.html


    Any further help is appreciated.

    Thanks!
     
  5. OTrap

    OTrap Jr. VIP Jr. VIP

    Joined:
    Jul 12, 2008
    Messages:
    2,286
    Likes Received:
    1,052
    Ah! Forgot to add jquery.js.

    It's working now. Thanks!
     
  6. sockpuppet

    sockpuppet Junior Member

    Joined:
    Nov 7, 2011
    Messages:
    155
    Likes Received:
    145
    good jaaab, good jaaab