This code checks for dead links. Since 3rd party Ajax requests are not allowed by browsers, I created a php file to check for dead links and my native jQuery code is:
function UrlExists(urlx) {
$.ajax({
url: "/chk.php?url=" + encodeURIComponent(urlx),
cache: false,
method: 'get',
success: function (data) {
if (data.indexOf("T") != -1) {
return true;
}
else {
return false;
}
}
});
}
$(document).ready(function () {
$("table[id^='row']").each(function () {
if (!UrlExists($(this).find("a[href$='mp3']").attr('href'))) {
$(this).remove();
}
})
});
While, I have made sure that
1) chk.php is working properly and return T on some URLs and on others not.
2) Old JS code is not being used
Still the problem is that above program removes all links. I also tried setting async to false but it does’nt help.
The problem is that you return within you success-callback, that return will not reach the outer function, thus
UrlExist()does not return anything as it is written today.You will either have to do the remove from within your success-callback, or call another function that remove the link, but that function would still have to be called from within your success-callback.