Skip to content

Instantly share code, notes, and snippets.

@zhugw
Created August 21, 2017 07:28
Show Gist options
  • Save zhugw/9ee818c464010f9eb7d2fcd947bbeb46 to your computer and use it in GitHub Desktop.
Save zhugw/9ee818c464010f9eb7d2fcd947bbeb46 to your computer and use it in GitHub Desktop.
Html ajax request and show result in table
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="Access-Control-Allow-Origin" content="*">
<title>Title</title>
<script src="https://cdn.bootcss.com/jquery/3.2.1/jquery.min.js"></script>
<style>
table{
text-align: center;
border-spacing: 0;
border-collapse: collapse;
border-bottom: 1px solid #ddd;
border-right: 1px solid #ddd;
}
table th{
border-top: 1px solid #ddd;
border-left: 1px solid #ddd;
}
table td{
border-top: 1px solid #ddd;
border-left: 1px solid #ddd;
}
#btn {
float: right;
width: 80px;
height: 30px;
border:0;
background-color: blue;
color: white;
cursor: pointer;
}
</style>
</head>
<body>
<div id="main" style="width: 1000px; margin: 0 auto;margin-top: 50px;">
<textarea id="conment" style="width: 100%;height: 100px;"></textarea>
<button id="btn" style="">提交</button>
<div id="tables" style="width: 100%;margin-top: 60px;"></div>
</div>
</body>
<script>
$("#btn").on("click", function () {
var conment = $.trim($("#conment").val());
console.log(conment);
$.ajax({
type: "post",
// async: false,
url: "http://localhost:8080/extract",
headers:{"Content-Type":"application/x-www-form-urlencoded"},
data:{text:conment},
dataType:"json",
success: function(msg) {
var html ='';
html+= '<table style="width: 100%;">';
html+= '<thead>';
html+= '<tr>';
html+= '<th>sentenceId</th>';
html+= '<th>category</th>';
html+= '<th>entity</th>';
html+= '<th>desc</th>';
html+= '</tr>';
html+= '</thead>';
html+= '<tbody>';
for(var i=0;i<msg.length;i++){
html += '<tr>';
html += '<td>'+ msg[i].sentenceId +'</td>';
html += '<td>'+ msg[i].category +'</td>';
html += '<td>'+ msg[i].entity +'</td>';
html += '<td>'+ msg[i].desc +'</td>';
html += '</tr>';
}
html+= '</tbody>';
html+= '</table>';
$("#tables").html(html);
}
});
})
</script>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment