admin
Ajax
原生Ajax
if (window.XMLHttpRequest)
{
// IE7+, Firefox, Chrome, Opera, Safari 浏览器执行代码
xhr=new XMLHttpRequest();
}
else
{
// IE6, IE5 浏览器执行代码
xhr=new ActiveXObject("Microsoft.XMLHTTP");
}
xhr.open('GET','index.php?module=Agent&action=Delete&id='+id,true);
xhr.onreadystatechange=function(){
if(xhr.readyState==4 && xhr.status==200){
state = JSON.parse(xhr.responseText)//JSON.parse函数 将json字符串转换成json对象。
if(state.code == 200){
layui.use('layer', function(){
var layer = layui.layer;
layer.msg(state.msg, {icon: 1});
setTimeout(function(){
window.location.reload();
},3000);
});
}
}
}
xhr.send();
JQ版
$.ajax({
url:'index.php?module=Agent&action=Delete',
type:'POST', //GET
async:true, //或false,是否异步
data:{
id:id
},
timeout:5000, //超时时间
dataType:'json', //返回的数据格式:json/xml/html/script/jsonp/text
success:function(data){
console.log(data);
},
})
return false;//阻止默认提交