英文:
Get console.log in HTML
问题
以下是翻译好的部分:
<!DOCTYPE html>
<html>
<title>Online Compile</title>
<body>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var ultimate_test_result = 24;
var to_compile = {
"LanguageChoice": "4",
"Program": $("#code").val(),
"Input": "",
"CompilerArgs" : ""
};
$.ajax ({
url: "https://rextester.com/rundotnet/api",
type: "POST",
data: to_compile
}).done(function(data) {
//alert(JSON.stringify(data));
console.log(data);
}).fail(function(data, err) {
alert("fail " + JSON.stringify(data) + " " + JSON.stringify(err));
});
});
});
</script>
<textarea id="code" rows="20" cols="100">
class Rextester {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</textarea><br>
<button id="run">Run</button>
<br>
</body>
</html>
英文:
I have written an online editor code which compiles java codes, the problem is that I get the output from the compiler as console.log()
Output is : {Warnings: null, Errors: null, Result: "Hello World!↵", Stats: "Compilation time: 0.72 sec, absolute running time:…mory peak: 35 Mb, absolute service time: 1,09 sec", Files: null, …}
I want the output to be shown in the HTML itself, any solution ??
So far my code is:
<!DOCTYPE html>
<html><title> Onile Compile</title
<body>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var ultimate_test_result = 24;
var to_compile = {
"LanguageChoice": "4",
"Program": $("#code").val(),
"Input": "",
"CompilerArgs" : ""
};
$.ajax ({
url: "https://rextester.com/rundotnet/api",
type: "POST",
data: to_compile
}).done(function(data) {
//alert(JSON.stringify(data));
console.log(data);
}).fail(function(data, err) {
alert("fail " + JSON.stringify(data) + " " + JSON.stringify(err));
});
});
});
</script>
<textarea id="code" rows="20" cols="100">
class Rextester {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</textarea><br>
<button id="run">Run</button>
<br>
</body>
</html>
答案1
得分: 1
你可以在HTML中放置一个带有ID的div,然后使用$("#result_id").html(data)
或$("#result_id").text(data)
。
<!DOCTYPE html>
<html>
<title>在线编译</title>
<body>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var ultimate_test_result = 24;
var to_compile = {
"LanguageChoice": "4",
"Program": $("#code").val(),
"Input": "",
"CompilerArgs" : ""
};
$.ajax ({
url: "https://rextester.com/rundotnet/api",
type: "POST",
data: to_compile
}).done(function(data) {
//alert(JSON.stringify(data));
console.log(data);
$("#result").text(data);
}).fail(function(data, err) {
alert("fail " + JSON.stringify(data) + " " + JSON.stringify(err));
});
});
});
</script>
<textarea id="code" rows="20" cols="100">
class Rextester {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</textarea><br>
<button id="run">Run</button><br>
<div id="result"></div>
</body>
</html>
英文:
You could place a div with ID in html and then use $("#result_id").html(data)' or '$("#result_id").text(data)
<!DOCTYPE html>
<html><title> Onile Compile</title
<body>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script>
$(document).ready(function(){
$("button").click(function(){
var ultimate_test_result = 24;
var to_compile = {
"LanguageChoice": "4",
"Program": $("#code").val(),
"Input": "",
"CompilerArgs" : ""
};
$.ajax ({
url: "https://rextester.com/rundotnet/api",
type: "POST",
data: to_compile
}).done(function(data) {
//alert(JSON.stringify(data));
console.log(data);
$("#result").text(data);
}).fail(function(data, err) {
alert("fail " + JSON.stringify(data) + " " + JSON.stringify(err));
});
});
});
</script>
<textarea id="code" rows="20" cols="100">
class Rextester {
public static void main(String[] args) {
System.out.println("Hello World!");
}
}
</textarea><br>
<button id="run">Run</button>
<br>
<div id="result"></div>
</body>
</html>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论