<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("數(shù)據(jù): " + JSON.stringify(data) + "\n狀態(tài): " + 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是異步的,數(shù)據(jù)的接受和下面方面的執(zhí)行示血,不產(chǎn)生沖突脑溢。
圖片.png
參考:
https://blog.csdn.net/Handsome2013/article/details/89809962
https://blog.csdn.net/qq_19301269/article/details/78588792