DoneJS StealJS jQuery ++ FuncUnit DocumentJS
3.0.0
2.3.27

 

  • Github
  • Twitter
  • Chat
  • Forum
  • Guides
  • Core
  • Ecosystem
    • can-construct-super
    • can-define-stream
    • can-fixture
      • types
        • Store
        • ajaxSettings
        • request
        • requestHandler
        • response
      • properties
        • delay
        • on
        • rand
        • store
    • can-fixture-socket
    • can-jquery
    • can-stache-converters
    • can-stream
    • can-vdom
    • can-view-import
    • can-zone
    • steal-stache
  • Infrastructure
  • Legacy
  • Bitovi
    • Bitovi.com
    • Blog
    • Consulting
    • Training
    • Open Source
  • Chat
  • Forum
  • Star
  • Follow @canjs
  • CanJS
  • /
  • Ecosystem
  • /
  • can-fixture
  • /
  • response
  • / On this page
    • response

      typedef
      • source

      response(status, body, headers, statusText)

      Used to detail a response.

      Example:

      fixture({url: "/todos/{action}"},
        function(request, response, headers, ajaxSettings){
          response(
              401,
              { message: "Unauthorized"},
              { "WWW-Authenticate": 'Basic realm="myRealm"'},
              "unauthorized");
        }
      });
      
      $.post("/todos/delete");
      

      You don't have to provide every argument to response. It can be called like:

      // Just body
      response({ message: "Hello World"});
      // status and body
      response(401, { message: "Unauthorized"});
      // body and headers
      response('{"message":"Unauthorized"}',{"WWW-Authenticate":'Basic realm="myRealm"'});
      // status, body statusText
      response(401, '{"message":"Unauthorized"}','unauthorized');
      

      The default statusText will be ok for 200 <= status < 300, status === 304 and error for everything else.

      Parameters

      1. status {Number}:

        The HTTP response code. Ex: 200.

      2. body {Object}:

        A JS object that will be serialized and set as the responseText of the XHR object, or the raw string text that will be set as the responseText of the XHR object.

      3. headers {Object}:

        An object of HTTP response headers and values.

      4. statusText {String}:

        The status text of the response. Ex: "ok" for 200.

      CanJS is part of DoneJS. Created and maintained by the core DoneJS team and Bitovi. Currently 3.0.0.