• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 677
  • Last Modified:

How to add Jquery variable

Hi,

I'm pretty new with Jquery so apologies if I don't know the correct naming conventions..

I've created a variable stored in localStorage but I can't seem to add it into an exisiting function.
I'm trying to add:
var RSSone = localStorage.getItem('RSSone');

Open in new window

Where the value of the item is an RSS feed such as http://feeds.bbci.co.uk/news/rss.xml?edition=int.

I'd like to add the RSS feed into the code below...

var newsfeed=new gfeedfetcher("rssfeeds", "rssfeedsclass", "_new")
newsfeed.addFeed("Ormiston School News", "http://www.ormistonsandwell.org.uk/RSS/News/");
newsfeed.addFeed("BBC Tech Feed",  "http://feeds.bbci.co.uk/news/technology/rss.xml");
newsfeed.displayoptions("label datetime snippet");
newsfeed.setentrycontainer("p");
newsfeed.filterfeed(10, "date");
newsfeed.init();

Open in new window


0
grahammiles
Asked:
grahammiles
  • 5
  • 4
1 Solution
 
Gurvinder Pal SinghCommented:
when you do,
var RSSone = localStorage.getItem('RSSone');

are you able to get the value of 'RSSone' in your application?
If yes, then why are you not able to use it?

Let me know if my understanding of your question is correct
0
 
grahammilesAuthor Commented:
I'm able to get RSSOne stored in localStorage but I can't seem to add it to the jquery script above. It just does nothing or kills it.

I thought something like this would work:

newsfeed.addFeed("RSS Feed One", $RSSone );

the code called for addFeed is:
gfeedfetcher.prototype.addFeed=function(label, url){
	this.feedlabels[this.feedlabels.length]=label
	this.feedurls[this.feedurls.length]=url
}

Open in new window

0
 
Gurvinder Pal SinghCommented:
did you tried this also
newsfeed.addFeed("RSS Feed One", RSSone );

why was the dollar sign required there?
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
grahammilesAuthor Commented:
I feel stupid now! I set it up as a global variable and that works fine - I thought the dollar sign declared a variable and had tried both...

It works as a global variable but still can't call it from local storage.
0
 
grahammilesAuthor Commented:
Almost there I hope...

If I set up localStorage as below, it stores the variable but comes up as 'undefined' when it tries to load the RSS feeds...

  localStorage.setItem('RSSone', '"http://www.abingdon.org.uk/atom/446/"'); //saves to the database, key/value
  document.write(localStorage.getItem("RSSone"));
  var feedOne = localStorage.getItem("RSSone");

Open in new window

0
 
Gurvinder Pal SinghCommented:
i think first line is asynchronous one.

there should be some delay in first and second line
0
 
grahammilesAuthor Commented:
I'm not sure how I would create a delay there? The second line is not actually needed, just there to help see if its working.
0
 
Gurvinder Pal SinghCommented:
are you able to check in the local storage that the value is setting correctly or not?
0
 
grahammilesAuthor Commented:
Yep. It writes to the page and I can see its there in Firebug.

I think just talking through it has helped me to solve it.

newsfeed.addFeed("Local Feed Test", localStorage.getItem("RSSone"));

Open in new window


Thanks for holding my hand!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 5
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now