4

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?

Billy Moon
  • 57,113
  • 24
  • 136
  • 237

1 Answers1

4

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'
});
nhahtdh
  • 55,989
  • 15
  • 126
  • 162
dandapereira
  • 757
  • 5
  • 6