Skip to content

Instantly share code, notes, and snippets.

@edubriguenti
Created October 9, 2014 14:49
Show Gist options
  • Save edubriguenti/6a041da45e759665cd78 to your computer and use it in GitHub Desktop.
Save edubriguenti/6a041da45e759665cd78 to your computer and use it in GitHub Desktop.
Checks if an URL is valid via JSONP
<rich:modalPanel minwidth="300" minheight="100" id="mensagemURLModal"
modal="true" resizeable="false" autosized="true">
<table width="250" border="0" cellpadding="4" cellspacing="0" align="center">
<tr>
<td align="center">
<div id="mensagemURL"></div>
</td>
</tr>
<tr>
<td align="center">
<h:commandButton styleClass="botaoAzul" value="OK" onclick="#{rich:component('mensagemURLModal')}.hide();"/>
</td>
</tr>
</table>
</rich:modalPanel>
function validarURL(){
//<![CDATA[
jQuery(function($){
url2 = $( "#incluirAssuntoModal\\:valorIncluir" ).val();
alert(url2);
$.ajax({
url: 'http://api.httpstatus.io/?url=http://'+url2,
type: "GET",
dataType: "jsonp",
success: function(data){
if (data.status == 'success'){
$("#mensagemURL").html("URL válida");
}else{
$("#mensagemURL").html("URL inválida");
}
#{rich:component('mensagemURLModal')}.show();
},
error: function(xhr, status, error) {
alert(status + '; ' + error);
}
});
});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment