在线引用jquery
<script src="https://code.jquery.com/jquery-3.1.1.min.js"></script>
简单模拟点击页面获取接口的值与id
<input id="ipt" />
document.onclick = function (){
var ipt = document.getElementById("ipt")
huoqu(ipt.value,1);// (input.value为参数nameEach,1为id)
}
url需要传的地址,ming请求get或者post,message参数(定义nameEach),获取的id
function aajax(url, ming, nameEach, id) {
var result = "";
$.ajax({
type: ming,
url: url,
async: false,
data: {
message: nameEach,
vidoid: id
},
success: function (ppl) {
result = ppl;
}
})
console.log(result);
return result;
}
在页面中获取数据
// 调用数据
function huoqu(nameEach, id) {
var hhh = aajax("/home2021/kavo0422_SetMeetMessage","post",nameEach,id);
console.log(hhh);
}
// str存储数据
var str = '';
// 获取相应的数据
function dd() {
var hhh = aajax("/home2021/kavo0422_SetMeetMessage","get";
console.log(hhh);
str = hhh.data;
}
// 页面调用
dd();
如果后台定义的参数不一样 封装的ajax名称也要改
function aajax2(url, ming, id) {
var result = ""
$.ajax({
type: ming,
url: url,
async: false,
data: {
id: id
},
success: function (ppl) {
result = ppl
}
})
console.log(result);
return result;
}
function qing(url,id){
var qingQiu = aajax2(url,"post", id)
console.log(qingQiu);
}
qing("地址",id)