<button type="submit" id="quety" class="btn btn-info" onclick="query()">查询</button>
<script>
function query()
{
$.ajax(
{
url:"/hello/data",
data:{},
type:"post",
dataType:"json",
success:function(data)
{
alert("数据: " + JSON.stringify(data) + "\n状态: " + status);
},
error: function() {
alert("error");
}
});
}
</script>
后台
@Controller
@RequestMapping("/hello")
public class HelloController {
@Autowired
private UserMapper userMapper;
@RequestMapping(value = "/data", method = RequestMethod.POST)
@ResponseBody
public List<User> data() {
List<User> list = new ArrayList<User>();
list=userMapper.findAll();
return list;
}
}
默认ajax是异步的,数据的接受和下面方面的执行,不产生冲突。
图片.png参考:
https://blog.csdn.net/Handsome2013/article/details/89809962
https://blog.csdn.net/qq_19301269/article/details/78588792
网友评论