Ejemplo REST en Javascript

window.onload = function() { console.log("%c JS funcionando!!",'background-color:black; color:lightgreen'); var mb = document.getElementById("myBtn"); mb.addEventListener("click", jsonparser1); }; function jsonparser1() { console.log("Evento click") var url = "https://httpbin.org/get"; $.ajax(url,{ method:"GET", dataType:"json", success: function(response){ document.getElementById("span").innerHTML ="<h2>Host:<font color='blue'>"+response.headers.Host +"</font><br/>Origin:<font color='blue'>" +response.headers.origin +"</font></h2>"; document.getElementById("spanDos").innerHTML ="<h2><font color='green'>Correcto!!</font></h2>"; },error: function(request, errorType, errorMsg){ alert("Ha ocurrido un error: "+errorMsg.toString()); } }); }
Se trata de un ejemplo del uso de $.ajax() de jQuery

Be the first to comment

You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.