In this code I am trying to compare two strings with jQuery. The current content of a div and the new content, loaded from a (currently) static page.
But it doesn’t work, when the loaded content is the same as the current content, it still loads the new content…
When I view the content vars, they really are equal (I used the JS alert).
$(document).ready(function () {
var refreshId = setInterval(function () {
$.get("ajaxGetEvents.aspx", function (data) {
if ($('#events').html() != data) {
$('#events').fadeOut('slow', function () {
$(this).load('ajaxGetEvents.aspx').fadeIn('slow');
});
} else {
alert("item is equal");
}
});
}, 5000);
});
I suspect you are not getting the values you expect for
$('#events').html()anddata.Can you use firebug or developer tools to place a breakpoint at your if statement and inspect the values?
Alternatively you could just throw in a couple of alerts to see what these contain… Example:
That said, if you are not familiar with using firebug or developer tools, now might be a good time to start using them. They will save you a lot of headaches in the future and they are infinitely better than alerts when it comes to debugging.