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

OTrap

Elite Member
Joined
Jul 12, 2008
Messages
2,314
Reaction score
1,064
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!
 
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 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.
 
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!
 
Ah! Forgot to add jquery.js.

It's working now. Thanks!
 
Back
Top