[英]Get console.log in 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()
我已经编写了一个编译 java 代码的在线编辑器代码,问题是我从编译器获得输出为
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, …}
输出是:
{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 ??我希望输出显示在 HTML 本身中,有什么解决方案吗??
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>
You could place a div with ID in html and then use $("#result_id").html(data)' or '$("#result_id").text(data)
您可以在 html 中放置一个带有 ID 的 div,然后使用
$("#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>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.