jquery - How to include external js if exists, else do nothing (ignore)? -


i have pieced jquery snippet using ajax call call external file, works great shown:

jquery.ajax({    type: "get",    url: "http://www.domain.com/external.js",    datatype: "script" }); 

i need (to create) external file under conditions, if not present, 404 error in browser console. want absolutely nothing (ignore) if file not present.

the closest related post found how include external html if exists, else nothing? doesn't nothing, runs function:

jquery(function() { jquery.ajax({     type: "get",     url: "http://www.domain.com/external.js",     cache: false,     datatype: "script"     success: function(html){         $('#test').html(html);     }   }); }); 

question: how go ignoring warnings if file not present, run file if is?

could this?

jquery(function() { jquery.ajax({     type: "get",     url: "http://www.domain.com/external.js",     cache: false,     datatype: "script"     success: ;     }   }); }); 

edit response lance:

because didn't know it! wow, easy? this?

try {    jquery.ajax({     type: "get",     url: "http://www.domain.com/external.js",     datatype: "script"   }); } catch(e){   /* move along */       } 

how using try/catch?

try{     /* stuff want */ }catch(e){     /* don't display error.  move along.  nothing see here. } 

Comments

Popular posts from this blog

PHP DOM loadHTML() method unusual warning -

python - How to create jsonb index using GIN on SQLAlchemy? -

c# - TransactionScope not rolling back although no complete() is called -