简体   繁体   English

Mockjax HTTP错误代码

[英]Mockjax HTTP error code

Is it possible to mock HTTP error codes, and other header information using mockjax? 是否可以使用mockjax模拟HTTP错误代码和其他头信息?

$.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'
});

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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