2013-07-05 52 views
4

是否可以使用mockjax來嘲笑HTTP錯誤代碼和其他頭信息?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); 
    } 
}); 

另外,是否有另一個庫可以?

回答

4

您可以設置錯誤的狀態碼,在「狀態」:

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