student.js
2.56 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
$(function(){
$('#CompileBtn').trigger('click');
$('#CompileBtn').on('click', function(){
console.log('编译' + teacher.getValue());
var el = document.querySelector('#CompileBtn')
var l = Ladda.create(el);
l.start();
var input = $('#input').val() || '';
var code = teacher.getValue();
var compileData = {
code: code,
langid: 10,
input: input
}
$.ajax({
type: "post",
url: gxb_api + "/submit/submitCode/api",
data: JSON.stringify(compileData),
dataType: "json",
contentType: "application/json",
success: function(data) {
console.log(data);
l.remove();
compileResult(data);
},
error: function(){
l.stop();
alert('错误');
}
});
})
// 编译结果
function compileResult(data){
if(data.result){
$('#cmpinfo').html('<p class="text-warning">' + data.cmpinfo.replace(/\n/g, "<br />") + "</p>");
$('#stderr').html('<p class="text-danger">' + data.stderr.replace(/\n/g, "<br />") + "</p>");
$('#output').html('<p class="text-success">' + data.output.replace(/\n/g, "<br />") + "</p>");
if(data.cmpinfo.length){
$('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
}else if(data.stderr.length){
$('#cmprun-tabs a[href="#stderr"]').tab('show');
}else if(data.output.length){
$('#cmprun-tabs a[href="#output"]').tab('show');
}
if(!data.cmpinfo.length){
$('#cmpinfo').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 编译已成功</p>');
}
if(!data.stderr.length){
$('#stderr').prepend('<p class="alert alert-success"><i class="glyphicon glyphicon-ok-sign"></i> 无输出错误</p>');
}
if(!data.output.length){
$('#output').prepend('<p class="alert alert-warning"><i class="glyphicon glyphicon-exclamation-sign"></i> 代码编译错误或者运行相关功能受限制</p>');
}
}else{
$('#cmpinfo').html('<p class="alert alert-danger"><i class="glyphicon glyphicon-exclamation-sign"></i> 云端编译超时,请稍后重新尝试</p>');
$('#cmprun-tabs a[href="#cmpinfo"]').tab('show');
}
}
})