-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
43 lines (39 loc) · 1.42 KB
/
Copy pathscript.js
File metadata and controls
43 lines (39 loc) · 1.42 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
var codeOfTextarea;
var langId;
var output;
var codeId;
var compileBtn = document.getElementById("compile");
compileBtn.addEventListener("click", function(){
document.getElementById("output").innerText = "Code compilation is in progress...";
codeOfTextarea = document.getElementById("codearea").value;
langId = document.getElementById("langId").value;
sendCodeForCompilation();
setTimeout(outputAfterCompilation,6000);
});
function sendCodeForCompilation(){
var sendreq=new XMLHttpRequest();
sendreq.open("POST","https://codequotient.com/api/executeCode");
sendreq.setRequestHeader("Content-Type", "application/JSON");
sendreq.send(JSON.stringify({ code:codeOfTextarea,langId:langId}));
sendreq.addEventListener("load",function(event){
codeId=JSON.parse(event.target.responseText);
});
}
function outputAfterCompilation(){
var getreq=new XMLHttpRequest();
getreq.open("GET","https://codequotient.com/api/codeResult/"+codeId.codeId);
getreq.send();
getreq.addEventListener("load",function(event){
fetchResultInOutput(JSON.parse(event.target.responseText))
})
}
function fetchResultInOutput(data){
var obj = JSON.parse(data.data);
console.log(obj);
if(obj.errors!=""){
document.getElementById("output").innerHTML=obj.errors;
}
else{
document.getElementById("output").innerHTML=obj.output;
}
}