简体   繁体   中英

Mockjax HTTP error code

Is it possible to mock HTTP error codes, and other header information using mockjax?

$.mockjax({
    url: '/some/webservice',
    dataType: 'html',
    responseText: '<div>Hello there</div>'
});

// Normal ajax request in your application
$.ajax({
    url: '/some/webservice',
    dataType: 'html',
    success: function(html) {
        alert('You said: ' + html);
    }
});

Alternatively, is there another library that can?

You can set the status code of the error, in the 'status':

$.mockjax({
  url: '/restful/api',
  // Server 500 error occurred
  status: 500,
  responseTime: 750,
  responseText: 'A text response from the server'
});

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM