IO

Provides utility that brokers HTTP requests through a simplified interface

defined in: base.js

Function Namespace

Attributes

  • IO. isLocal {Boolean} <static> whether current application is a local application (protocal is file://,widget://,about://)

Methods

  • IO. get (url, data, callback, dataType) <static> perform a get request
  • IO. getConfig () <static> get default config value for io request
  • IO. getJSON (url, data, callback) <static> perform a get request to fetch json data from server
  • IO. jsonp (url, data, callback) <static> preform a jsonp request
  • IO. post (url, data, callback, dataType) <static> preform a post request
  • IO. serialize (formElement) <static> form serialization
  • IO. setupConfig (setting) <static> name-value object that set default config value for io request
  • IO. upload (url, form, data, callback, dataType) <static> submit form without page refresh

Events

  • complete (e) fired after request completes (success or error)
  • error (e) fired after request occurs error
  • send (e) fired before sending request
  • start (e) fired before generating request object
  • success (e) fired after request succeeds

Function Namespace Detail

  • IO (c)
    Provides utility that brokers HTTP requests through a simplified interface
    Parameters
    •   c {Object}
      name-value of object to config this io request.
      all values are optional.
      default value can be set through io.setupConfig
    •   c.url {String}
      request destination
    •   c.type {String}
      request type. eg: "get","post"
      Default: "get"
    •   c.contentType {String}
      Default: "application/x-www-form-urlencoded; charset=UTF-8"
      Data will always be transmitted to the server using UTF-8 charset
    •   c.accepts {Object}
      Default: depends on DataType.
      The content type sent in request header that tells the server
      what kind of response it will accept in return.
      It is recommended to do so once in the io.setupConfig
    •   c.async {Boolean}
      Default: true
      whether request is sent asynchronously
    •   c.cache {Boolean}
      Default: true ,false for dataType "script" and "jsonp"
      if set false,will append _ksTs=Date.now() to url automatically
    •   c.contents {Object}
      a name-regexp map to determine request data's dataType
      It is recommended to do so once in the io.setupConfig
    •   c.context {Object}
      specify the context of this request's callback (success,error,complete)
    •   c.converters {Object}
      Default:{text:{json:JSON.parse,html:mirror,text:mirror,xml:KISSY.parseXML}}
      specified how to transform one dataType to another dataType
      It is recommended to do so once in the io.setupConfig
    •   c.crossDomain {Boolean}
      Default: false for same-domain request,true for cross-domain request
      if server-side jsonp redirect to another domain ,you should set this to true
    •   c.data {Object}
      Data sent to server.if processData is true,data will be serialized to String type.
      if value if an Array, serialization will be based on serializeArray.
    •   c.dataType {String}
      return data as a specified type
      Default: Based on server contentType header
      "xml" : a XML document
      "text"/"html": raw server data
      "script": evaluate the return data as script
      "json": parse the return data as json and return the result as final data
      "jsonp": load json data via jsonp
    •   c.headers {Object}
      additional name-value header to send along with this request.
    •   c.jsonp {String}
      Default: "callback"
      Override the callback function name in a jsonp request. eg:
      set "callback2" , then jsonp url will append "callback2=?".
    •   c.jsonpCallback {String}
      Specify the callback function name for a jsonp request.
      set this value will replace the auto generated function name.
      eg:
      set "customCall" , then jsonp url will append "callback=customCall"
    •   c.mimeType {String}
      override xhr's mime type
    •   c.processData {Boolean}
      Default: true
      whether data will be serialized as String
    •   c.scriptCharset {String}
      only for dataType "jsonp" and "script" and "get" type.
      force the script to certain charset.
    •   c.beforeSend {Function}
      beforeSend(xhrObject,config)
      callback function called before the request is sent.this function has 2 arguments
      1. current KISSY xhrObject
      2. current io config
      note: can be used for add progress event listener for native xhr's upload attribute see XMLHttpRequest2
    •   c.success {Function}
      success(data,textStatus,xhr)
      callback function called if the request succeeds.this function has 3 arguments
      1. data returned from this request with type specified by dataType
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    •   c.error {Function}
      success(data,textStatus,xhr)
      callback function called if the request occurs error.this function has 3 arguments
      1. null value
      2. status of this request with type String,such as "timeout","Not Found","parsererror:..."
      3. XhrObject of this request , for details IO.XhrObject
    •   c.complete {Function}
      success(data,textStatus,xhr)
      callback function called if the request finished(success or error).this function has 3 arguments
      1. null value if error occurs or data returned from server
      2. status of this request with type String,such as success:"ok", error:"timeout","Not Found","parsererror:..."
      3. XhrObject of this request , for details IO.XhrObject
    •   c.timeout {Number}
      Set a timeout(in seconds) for this request.if will call error when timeout
    •   c.serializeArray {Boolean}
      whether add [] to data's name when data's value is array in serialization
    •   c.xhrFields {Object}
      name-value to set to native xhr.set as xhrFields:{withCredentials:true}
    •   c.username {String}
      a username tobe used in response to HTTP access authentication request
    •   c.password {String}
      a password tobe used in response to HTTP access authentication request
    •   c.xdr {Object}
      cross domain request config object
    •   c.xdr.src {String}
      Default: kissy's flash url flash sender url
    •   c.xdr.use {String}
      if set to "use", it will always use flash for cross domain request even in chrome/firefox
    •   c.xdr.subDomain {Object}
      cross sub domain request config object
    •   c.xdr.subDomain.proxy {String}
      proxy page,eg:
      a.t.cn/a.htm send request to b.t.cn/b.htm:
      1. a.htm set document.domain='t.cn'
      2. b.t.cn/proxy.htm 's content is <script>document.domain='t.cn'</script>
      3. in a.htm , call io({xdr:{subDomain:{proxy:'/proxy.htm'}}})
    Returns

Attributes Detail

  • IO. isLocal {Boolean} <static> whether current application is a local application (protocal is file://,widget://,about://)

Methods Detail

  • IO. get (url, data, callback, dataType) <static> view source
    perform a get request
    Defined in:ajax.js.
    Parameters
    •   url {String} request destination
    • [ data ] {Object} name-value object associated with this request
    •   callback {Function()}
      success callback when this request is done with parameter
      1. data returned from this request with type specified by dataType
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    • [ dataType ] {String} the type of data returns from this request ("xml" or "json" or "text")
    Returns
  • IO. getConfig () <static> view source
    get default config value for io request
    Returns
    • {Object}
  • IO. getJSON (url, data, callback) <static> view source
    perform a get request to fetch json data from server
    Defined in:ajax.js.
    Parameters
    •   url {String} request destination
    • [ data ] {Object} name-value object associated with this request
    •   callback {Function()}
      success callback when this request is done
      with parameter
      1. data returned from this request with type JSON
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    Returns
  • IO. jsonp (url, data, callback) <static> view source
    preform a jsonp request
    Defined in:ajax.js.
    Parameters
    •   url {String} request destination
    • [ data ] {Object} name-value object associated with this request
    •   callback {Function()}
      success callback when this request is done
      with parameter
      1. data returned from this request with type specified by dataType
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    Returns
  • IO. post (url, data, callback, dataType) <static> view source
    preform a post request
    Defined in:ajax.js.
    Parameters
    •   url {String} request destination
    • [ data ] {Object} name-value object associated with this request
    •   callback {Function()}
      success callback when this request is done
      with parameter
      1. data returned from this request with type specified by dataType
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    • [ dataType ] {String} the type of data returns from this request ("xml" or "json" or "text")
    Returns
  • IO. serialize (formElement) <static> view source
    form serialization
    Defined in:ajax.js.
    Parameters
    •   formElement {HTMLElement[]|HTMLElement|NodeList} form elements
    Returns
    • {String} serialized string represent form elements
  • IO. setupConfig (setting) <static> view source
    name-value object that set default config value for io request
    Parameters
    •   setting {Object} for details see io
  • IO. upload (url, form, data, callback, dataType) <static> view source
    submit form without page refresh
    Defined in:ajax.js.
    Parameters
    •   url {String} request destination
    •   form {HTMLElement|NodeList} element tobe submited
    • [ data ] {Object} name-value object associated with this request
    •   callback {Function()}
      success callback when this request is done
      with parameter
      1. data returned from this request with type specified by dataType
      2. status of this request with type String
      3. XhrObject of this request , for details IO.XhrObject
    • [ dataType ] {String} the type of data returns from this request ("xml" or "json" or "text")
    Returns

Events Detail

  • complete (e) view source
    fired after request completes (success or error)
    Parameters
  • error (e) view source
    fired after request occurs error
    Parameters
  • send (e) view source
    fired before sending request
    Parameters
  • start (e) view source
    fired before generating request object
    Parameters
  • success (e) view source
    fired after request succeeds
    Parameters
blog comments powered by Disqus
Top