views:

20

answers:

2

The following does not seem to be working properly.

    success: function(results) 
    { 
        var $results = $(results);

        $results.find('a[href$=".exe"]').each(function(){
            if (FileExists(this.href) == false) {
               $(this).parent().remove(); 
            } 
        }); 

        $("#divSearchResults").empty().append($results);
    }

It should be removing any .exe links from results then appending the modified results to screen.

EDIT 1: Here is the script for the FileExists function:

function FileExists(path) {
    var fso = new ActiveXObject("Scripting.FileSystemObject");

    FileExist = fso.FileExists(path);

    if (FileExist == true) {
        return true
    } else {
        return false
    }
}

EDIT 2: results contains something like this:

<div><a href="link1.xls">link 1</a></div>  
<div><a href="link2.exe">link 2</a></div>  
<div><a href="link3.doc">link 3</a></div>  
<div><a href="link4.aspx">link 4</a></div>  
A: 

Kind of a hunch here, FileExists uses an AJAX call? In that case its asynchronous an will not return anything reliable since it exits the current flow of the application.

Kristoffer S Hansen
@Kristoffer S Hansen: I've updated the original question to show the FileExists function.
oshirowanen
+1  A: 

After some testing I'm thinking the problem is with $(this).parent().remove() and your results, if you look at this fiddle versus this fiddle, the first one doesnt work, but the second one works after we wrap it in a span, simply so the $results wont turn out empty.

Kristoffer S Hansen
Interestingly enough, that works! Thanks.
oshirowanen