// Mock.mock( rurl, rtype, template ) Mock.mock(/\.json/, 'get', { type: 'get' }) Mock.mock(/\.json/, 'post', { type: 'post' }) $.ajax({ url: 'hello.json', type: 'get', dataType: 'json' }).done(function (data, status, jqXHR) { $('<pre>').text(JSON.stringify(data, null, 4)) .appendTo('body') }) $.ajax({ url: 'hello.json', type: 'post', dataType: 'json' }).done(function (data, status, jqXHR) { $('<pre>').text(JSON.stringify(data, null, 4)) .appendTo('body') })
<!-- (必选)加载 Mock --> <script src="http://mockjs.com/dist/mock.js"></script>