环境:
1.jQuery v2.1.1
2.ThinkPHP 3.2.3
HTML页面:
<button type="button" id="cat" onclick="return showList()" class="btn btn-primary pull-right">删除</button>
<script type="text/javascript">
function showList(){
// $.get("{:U(‘ajax‘)}",
// function(data){
// console.log(data);
// });
$.ajax({
url: ‘{:U("ajax")}‘,
type: ‘get‘,
dataType: ‘json‘,
data: ‘‘,
})
.done(function(data) {
console.log(data);
})
.fail(function() {
console.log("error");
})
.always(function() {
console.log("complete");
});
}
</script>
PHP页面:
public function ajaxAction(){
$data[‘status‘] = 1;
$data[‘content‘] = ‘content‘;
$this->ajaxReturn($data);
}
结果: