0

I am using RightJS (very similar to jQuery) on a site I'm working on. I am loading an element on the page with the result of a request like so:

var comp = $('completed_step');
if(comp != null) comp.load("/brew/completed_step");

This works but I am trying to find a way to only load the element if the result of the request for 'brew/current_step' is different than the value currently loaded in the element. Is there an easy way to accomplish that?

CRUSADER
  • 5,486
  • 3
  • 28
  • 64
PICyourBrain
  • 9,976
  • 26
  • 91
  • 136

1 Answers1

0

You need to compare the value of the current element with what is loaded.

var comp2;
var comp = $('completed_step'); //I'm assuming this refers to some value
if( comp != null || comp != "" ){
    comp2 = load("/brew/completed_step");
}

if( comp != comp2 ){
    comp = comp2;
}

Keep in mind, I'm not familiar with RightJS, so this might be wrong, but should give you the right idea.

Edit:

It looks like the Xhr module in rightJS takes an object that allows you to specify what to do when the process has completed.

http://rightjs.org/docs/xhr#load

Xhr.load('/some/url', {
  onSuccess: function(request) {
    // do something about it
  }
});

That's from their example in the documentation.

Trendy
  • 460
  • 2
  • 12
  • This looks close to what I'm looking for but it doesn't quite work. It seems as though in RightJS the load() function is non-blocking. So in your example comp2 is aways null when it gets to the comparison. – PICyourBrain Aug 24 '13 at 14:41
  • The load method takes an object that contains completed, success, and failure callbacks that you can use to accomplish what you're trying to do. – Trendy Aug 24 '13 at 21:34