javascript - Edit returned results before appending on screen -


i have following script need combine somehow. each function works individually @ moment.

// check if file exists clientside function fileexists(path) {     var fso = new activexobject("scripting.filesystemobject");      fileexist = fso.fileexists(path);      if (fileexist == true){         return true     } else {         return false     } }  // links database function getsearchresults() {     var search;      search = $(".txtheadersearch").val();       $.ajax({         url: 'results.aspx',         type: 'post',         data: { strphrase:search },         success: function(results) {              // need somehow stop .exe links appearing on screen if fileexists == false             $("#divsearchresults").empty().append(results);          }     }); }  // returned data looks <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>  

is possible somehow integrate fileexists function ajax success function prevent .exe links appearing on clients screen if exe file in question not exist on clients computer?

edit 1: following giving me object not support property or method error:

    success: function(results)      {          results.find('a[href$=".exe"]').each(function(){              if (fileexists(this.href)) {                $(this).parent().remove();              }          });           $("#divsearchresults").empty().append(results);      } 

edit 2: no longer giving error, not remove non existant exe files either.

    success: function(results)      {          $(results).find('a[href$=".exe"]').each(function(){              if (fileexists(this.href)) {                $(this).parent().remove();              }          });           $("#divsearchresults").empty().append(results);      } 

edit 3: not work either.

    success: function(results)      {          var $results = $(results);          $results.find('a[href$=".exe"]').each(function(){             if (! fileexists(this.href)) {                $(this).parent().remove();              }          });           $("#divsearchresults").empty().append($results);     } 

you this, attribute ends selector

$(results).find('a[href$=".exe"]').parent().remove(); 

based on experienced, line not work. if happens you, this,

var results = $('<div>').html(results).find('a[href$=".exe"]').parent().remove(); results = results.html(); 

then result have line this,

<div><a href="link1.xls">link 1</a></div>  <div><a href="link3.doc">link 3</a></div>  <div><a href="link4.aspx">link 4</a></div> 

updated comment below.

$(results).find('a[href$=".exe"]').each(function(){     if (! fileexists(this.href)) { // uses href path...        $(this).parent().remove();     } }); 

Comments

Popular posts from this blog

ASP.NET/SQL find the element ID and update database -

jquery - appear modal windows bottom -

c++ - Compiling static TagLib 1.6.3 libraries for Windows -