56 lines
1.0 KiB
HTML
56 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<title>Title</title>
|
|
</head>
|
|
<body>
|
|
|
|
<input type="text" placeholder="输入关键词">
|
|
|
|
<button>搜索</button>
|
|
|
|
<div class="result">
|
|
|
|
</div>
|
|
|
|
</body>
|
|
<script src='//cdn.bootcss.com/jquery/3.1.1/jquery.min.js'></script>
|
|
<script>
|
|
|
|
$("button").on('click', function () {
|
|
console.log( $("input").val() )
|
|
$.ajax({
|
|
type: "GET",
|
|
url: "http://127.0.0.1/cp/index.php",
|
|
data: {
|
|
menu: $("input").val(),
|
|
page: 1,
|
|
limit: 10
|
|
},
|
|
success: function (res) {
|
|
const data = JSON.parse(res);
|
|
if (data.result == null) {
|
|
$(".result").empty();
|
|
$(".result").append(`<h2>没有数据</h2>`)
|
|
} else {
|
|
renderPage(data)
|
|
}
|
|
},
|
|
error: function (err) {
|
|
console.log(err)
|
|
}
|
|
});
|
|
});
|
|
|
|
function renderPage(data) {
|
|
console.log(data)
|
|
$(".result").empty();
|
|
data.result.data.forEach((val)=>{
|
|
$(".result").append(`<p>${val.title}</p>`)
|
|
})
|
|
}
|
|
|
|
|
|
</script>
|
|
</html> |