I'm not sure what I'm missing so thought I'd throw this up here. Below is an .ajaxComplete method that is not working correctly. I need to compare the URL the action is coming from with the URL from the action I want this code to be executed after.
This is an ASP MVC site, so I use the helper to grab the URL from the appropriate controller action. I then use the settings object to determine where the URL from the source of the current Ajax call (I have a couple on this page so need to use this to differentiate).
As you can see from the screen shot, both the url variable and settings.url contain the same value. I also set an alert to check for the length of each, and the alert comes back with a length of 35 for both.
However... this code routinely fails the if condition (I cannot get the alert("here") to fire). I'm relatively new to jQuery so I'm wondering if this is the correct way to compare two strings? FYI - I originally wrote the condition to be
if(settings.url == url)
however I could not get this to pass either.
//Tie completion of GetChannel Ajax call to execution of
//getDrmTerritory instead of using .change event on
//Market Segment drop down
$(document).ajaxComplete(function (event, xhr, settings) {
var url = '@Url.Action("GetChannel", "AgentTranmsission")';
alert(url.length + " " + settings.url.length);
alert("about to check");
if (String(settings.url) == String(url)) {
alert("here");
var channel = $.trim($('#channelName').text());
if ($('#AlignmentM:radio').is(':checked')) {
if ($('#MailingZip').val() != "" && $('#MailingState').val() != "" && channel != "") {
getDrmTerritory($('#MailingZip').val(), $('#MailingState').val(), channel);
} else if (channel != "") {
$('#territoryName').text("");
$('#Region').val("");
}
}
else if ($('#AlignmentL:radio').is(':checked')) {
if ($('#LocationZip').val() != "" && $('#LocationState').val() != "" && channel != "") {
getDrmTerritory($('#LocationZip').val(), $('#LocationState').val(), channel);
} else if (channel != "") {
$('#territoryName').text("");
$('#Region').val("");
}
}
}
alert("end");
});
EDIT
Here is a screen shot of (settings.url == url) evaluated in Chrome's console

and here is the alert that tests alert(url.length + " " + settings.url.length);
