Warning:
This wiki has been archived and is now read-only.

XMLHttpRequest

From Client and Server JavaScript APIs Community Group
Jump to: navigation, search

Introduction

XMLHttpRequest has from the beginning been defined as usable in either sync or async mode

The editor draft of the new edition (level 2) of the specification now forbid the async mode in the "document environment" (the main UI thread) where it would block user interaction It is then more explicit that synchronous APIs are not bad as long as they are not running in the main UI thread (and then ok for worker and multi-threaded contexts)

13. If async is false, the JavaScript global environment is a document environment, and either the anonymous flag is set, the timeout attribute value is not zero, the withCredentials attribute value is true, or the responseType attribute value is not the empty string, throw an "InvalidAccessError" exception and terminate these steps.

-> https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-open()-method

It also specify that if in a "worker environment", the response body is not exposed as a DOM Object in the response property which is then set to null

The document response entity body is either a document representing the response entity body or null. If the document response entity body has no value assigned to it let it be the return value of the following algorithm:
2. If the JavaScript global environment is a worker environment, return null and terminate these steps.

-> https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#response-entity-body

Setting the responseType attribute to "document" is cancelled in a "worker environment"

'4.7.7 The responseType attribute'
Setting the responseType attribute must run these steps:
2. If the JavaScript global environment is a document environment and the synchronous flag is set, throw an "InvalidAccessError" exception and terminate these steps.
3. If the JavaScript global environment is a worker environment and the given value is "document", terminate these steps.

-> https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responsetype-attribute

The responseXML attribute is then meant, in worker environment, at best to return null (value set in the internal “document response entity body"), or, if responseType is not empty string (as previously said it can not be set to "document"), it will throw an "InvalidState" error

The responseXML attribute must return the result of running these steps:
1. If responseType is not the empty string or "document", throw an "InvalidStateError" exception and terminate these steps.
4. Return the document response entity body.

-> https://dvcs.w3.org/hg/xhr/raw-file/tip/Overview.html#the-responsexml-attribute


Contacts

We are looking for representatives of this HTML5 API to discuss of potentially needed updates to consider server-side implementations

Debate

  • Server-Side API should not have Cross Origin Resource Sharing constraints. It may simulate this part of the API to remain compatible with client-side code
  • Some forbidden HTTP header access might be allowed on server side
  • XML not being mandatory any more an alias "HTTPRequest" might be defined for the XMLHttpRequest constructor


SSJS Implementations

Native

GPSEE

  • At the moment, this mostly follows the v1 spec.
  • Does not support XML/HTML parsing
  • Does not support Events (from V2 spec)
  • This is SYNCHRONOUS, as async requires a reactor

source: https://code.google.com/p/gpsee/source/browse/modules/xhr/xhr.js


SilkJS

An implementation is available:


Wakanda

XMLHttpRequest is partially implemented:


Third party module

Node.js

Node.js provide a different API called http.request:

A third party module with the W3C API exists: node-xmlhttprequest

References