1

I am using jFeed to parse an RSS feed and I would like to modify an outside variable (or array) from the function executed upon "success". This is a simple version of the code:

var testVariable = "Original";

jQuery.getFeed({
   url: rssFeed,
   success: function(feed) {
      testVariable = "New Value";
   }
});

When I output "testVariable", it still has the original value "Original". Is something wrong with my code?

The purpose of this is to apply the same logic to an array instead of a variable, so I can load the feed's contents into a global Javascript array.

Any help will be greatly appreciated.

Ralph
  • 397
  • 1
  • 4
  • 16
  • I will comment because this is really a debugging problem. If the variable is not changing it is because the success function is *not* being called. So to verify add an `alert` inside the success function, or implement an `onerror` function. – Josiah Ruddell Jan 11 '11 at 22:07
  • I just added an alert() and it's executing properly, so the success function is being called. But testVariable remains unchanged. Any ideas? – Ralph Jan 11 '11 at 22:13
  • When are you looking at the value of `testVariable`? the code does not execute sequentially, the part in the success function happens after an asynchronous callback. – Josiah Ruddell Jan 11 '11 at 22:15
  • You're right. I see the problem now. I need to call the value of testVariable from within the success function. Otherwise it's picking up the old value. Now it works. Thanks a lot! – Ralph Jan 11 '11 at 22:23

0 Answers0