Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
See more:
I have 2 JavaScript files.

1. Contains 2 Global Javascript variables as below.

JavaScript
var strStartdate;
var strEndDate;


2. This file has a variable as below

JavaScript
            var rowData =

'{"kind":"analytics#gaData","id":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:76546294&dimensions=ga:date&metrics=ga:uniquePageviews,ga:bounces&start-date=2014-01-01&end-date=2014-04-25","query":{"start-date":2014-01-01,"end-date":2014-04-25,"ids":"ga:76546294","dimensions":"ga:date","metrics":["Unique Page views","Bounces"],"start-index":1,"max-results":1000},"itemsPerPage":1000,"totalResults":115,"selfLink":"https://www.googleapis.com/analytics/v3/data/ga?ids=ga:76546294&dimensions=ga:date&metrics=ga:uniquePageviews,ga:bounces&start-date=' + strStartDate + '&end-date=' + strStartDate + ' ","profileInfo":{"profileId":"76546294","accountId":"289147","webPropertyId":"UA-289147-1","internalWebPropertyId":"456104","profileName":"US - Institutional Investors - NP Microsite","tableId":"ga:76546294"},"containsSampledData":false,"columnHeaders":[{"name":"ga:date","columnType":"DIMENSION","dataType":"STRING"},{"name":"ga:uniquePageviews","columnType":"METRIC","dataType":"INTEGER"},{"name":"ga:bounces","columnType":"METRIC","dataType":"INTEGER"}],"totalsForAllResults":{"ga:uniquePageviews":"2663","ga:bounces":"1048"},"rows":[["20140101","75","60"],["20140102","173","108"],["20140103","98","76"],["20140104","1","1"],["20140105","4","2"],["20140106","14","8"],["20140107","11","7"],["20140108","23","10"],["20140109","21","5"],["20140110","45","4"],["20140111","24","0"],["20140112","5","2"],["20140113","33","4"],["20140114","41","7"],["20140115","25","9"],["20140116","16","7"],["20140117","19","8"],["20140118","9","5"],["20140119","7","2"],["20140120","5","5"],["20140121","25","6"],["20140122","15","11"],["20140123","42","3"],["20140124","2","2"],["20140125","2","1"],["20140126","4","1"],["20140127","23","6"],["20140128","16","3"],["20140129","39","8"],["20140130","9","6"],["20140131","18","7"],["20140201","6","6"],["20140202","5","3"],["20140203","31","15"],["20140204","21","7"],["20140205","43","6"],["20140206","19","6"],["20140207","25","7"],["20140208","4","2"],["20140209","5","2"],["20140210","21","9"],["20140211","20","8"],["20140212","18","11"],["20140213","17","7"],["20140214","5","4"],["20140215","3","2"],["20140216","6","2"],["20140217","8","5"],["20140218","35","10"],["20140219","20","13"],["20140220","14","9"],["20140221","19","6"],["20140222","20","4"],["20140223","6","3"],["20140224","20","10"],["20140225","53","9"],["20140226","20","9"],["20140227","42","12"],["20140228","34","8"],["20140301","5","4"],["20140302","11","7"],["20140303","16","9"],["20140304","20","5"],["20140305","25","7"],["20140306","26","11"],["20140307","38","10"],["20140308","10","3"],["20140309","10","5"],["20140310","21","7"],["20140311","17","9"],["20140312","17","6"],["20140313","46","10"],["20140314","33","6"],["20140315","13","4"],["20140316","27","9"],["20140317","19","10"],["20140318","38","15"],["20140319","19","7"],["20140320","22","11"],["20140321","34","17"],["20140322","2","1"],["20140323","12","3"],["20140324","42","8"],["20140325","30","7"],["20140326","21","8"],["20140327","64","36"],["20140328","24","5"],["20140329","25","1"],["20140330","16","2"],["20140331","55","4"],["20140401","37","12"],["20140402","42","17"],["20140403","37","23"],["20140404","40","13"],["20140405","15","3"],["20140406","12","8"],["20140407","23","11"],["20140408","20","11"],["20140409","18","9"],["20140410","21","9"],["20140411","27","18"],["20140412","4","4"],["20140413","7","6"],["20140414","12","6"],["20140415","27","9"],["20140416","28","9"],["20140417","18","13"],["20140418","10","3"],["20140419","3","3"],["20140420","5","3"],["20140421","26","9"],["20140422","28","6"],["20140423","27","2"],["20140424","17","6"],["20140425","17","9"]]}';


In the URL Start-Date & End-Date must be filled with the global (globalsvar.js) strStartDate & strEndDate. So what should I do for the passing? Could someone help me to solve this matter?

Thanks & regards,
Chiranthaka
Posted
Updated 16-Jul-14 20:44pm
v2

Use this to store local data www.amplify.com[^]

/*store data with index "exam"*/
amplify.store("exam", "what ever you want to strore/ even objects");

/*retrieve data with index "exam"*/
var data = amplify.store("exam");
 
Share this answer
 
v2
Comments
Chiranthaka Sampath 17-Jul-14 6:32am    
does this answer make any sence?
DiponRoy 17-Jul-14 6:43am    
why don't save the values of Start-Date & End-Date using
amplify.store("Start-Date", "");
amplify.store("End-Date", "");
rather than the global variables;
Chiranthaka Sampath 17-Jul-14 7:01am    
Ok pal then my webservice is like this.

googleURL= 'https://www.googleapis.com/analytics/v3/data/ga?ids=ga%3A76546294&dimensions=ga%3Asource&metrics=ga%3Ausers&filters=ga%3Asource!%3D(direct)&sort=-ga%3Ausers&start-date=' + strStartDate + '&end-date=' + strEndDate + '&max-results=10';

Then how am I suppossed to fill the dates for 'start-date' & 'to-date'. This webservice URL is declared as a variable in a different JavaScript file named Script.js. Can you explain that also please.

Thanks & regards,
Chiranthaka
can you do something like this,
http://jsfiddle.net/qLPSm/[^]
C#
var urlHelper = (function(url){
    url.defaults = {
        startDate: '',
        endDate: ''
    };

    url.full = function(){
        return 'start data :' + url.defaults.startDate +' end date: ' +url.defaults.startDate;
    }

}(url = urlHelper || {}));


/*assign value*/
$(function(){
    url.defaults.startDate = 'hi';
    url.defaults.endDate = 'bye';
});


$(document).ready(function(){
    alert(url.full());
    /*change values again*/
    url.defaults.startDate = 'tes1';
    url.defaults.endDate = 'tes2';
    alert(url.full());
});



here if urlHelper is placed in any page, you can use it like this from any page.
 
Share this answer
 
v2
Comments
Chiranthaka Sampath 17-Jul-14 22:55pm    
If I use this code snippet in an external JavaScript file, how can I pass the form textboxes' data to the startdate & enddate variables?
I have got the answer. See it in the follwoing post.

JavaScript Function That Accepts External HTML Form Date.[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900