1. 劫持请求,返回模拟数据: 用于前后台对接前数据模拟
相比于静态json文件而言:代码完成后不必修改源文件对应的接口调用、可模拟增删改查
2.实例代码
<!doctype html> <html lang="en"> <head> <meta charset="UTF-8"> <title>Document</title> </head> <body> <script src="https://common.cnblogs.com/script/jquery.js"></script> <script src="http://mockjs.com/dist/mock.js"></script> <script type="text/javascript"> // mock Mock.mock('http://seed.gtafe.com:9998/Account/Login', { 'name': '@name', 'age|1-100': 100, 'city': '@city' }); </script> <script> // code $.ajax({ url: 'http://seed.gtafe.com:9998/Account/Login', dataType: 'json' }).done(function(data, status, xhr) { console.log(data, status, xhr); console.log( JSON.stringify(data, null, 4) ) }); </script> </body> </html>
3.相关文章