Ir al contenido principal
Cross Origen Sintax Highlighter
XHR
","
","");
a=a.replace(/njljljl/g, "");
a=a.replace(/nblblbl/g,"");
a=a.replace(/nhlhlhl/g, "");
return a;
}
function Req (method = _dMethod, url = _dUrl, status = _dStatus, response = _dResponse, headers = _dHeaders) {
this.method = method;
this.url = url;
this.status = status;
this.response = response;
this.headers = headers;
this.show = function () { alert(this.method + endl + this.url + endl + this.status + endl + this.headers + endl + this.response) };
}
function SendRequest (obj) {
xhr = new XMLHttpRequest();
xhr.open(obj.method, obj.url, 0);
xhr.onreadystatechange = function() {
if (xhr.readyState == 4) {
if(xhr.status == 200) {
obj.headers = xhr.getAllResponseHeaders();
obj.response = xhr.responseText;
getInputData("#HeadersArea", "value", obj.headers);
getInputData("#ResponseArea", "innerHTML", ehtmlEntities(obj.response));
} else {
/* db alert("Status: " + xhr.status); */
}
} else {
/* db alert("readyState " + xhr.readyState); */
}
}
/* db alert("Sending Request"); */
xhr.send();
}
function getInputData (selector, attribute, newValue) {
var nValue = newValue;
/* db alert("Selector: " + selector + "\nAttribute: " + attribute + "\nnewValue " + nValue); */
if (!nValue) {
return document.querySelector(selector)[attribute];
} else {
document.querySelector(selector)[attribute] = nValue;
}
return 0;
}
function main () {
var _;
var err = 0;
var responseHolder;
var response;
myReq = new Req();
myReq.method = getInputData("#Method", "value");
myReq.url = CORSHOSTIP + getInputData("#Url", "value");
/* db myReq.show(); */
SendRequest(myReq);
return 0;
}
bSendReq = document.querySelector("#SendReq");
bSendReq.addEventListener("click", function () { main()});
})();
Comentarios
Publicar un comentario