Skip to main content

Bug Tracker

Side navigation

#13862 closed feature (worksforme)

Opened May 07, 2013 07:21AM UTC

Closed April 30, 2014 01:37PM UTC

Add possibility of passing arguments to XMLHttpRequest constructor

Reported by: Veneti Owned by: jaubourg
Priority: high Milestone: 1.next/2.next
Component: ajax Version: 1.9.1
Keywords: Cc:
Blocked by: Blocking:
Description

Making AJAX requests on Firefox OS (operating system, not regular browser) does not work unless XMLHttpRequest is created in the following way:

var xhr = new window.XMLHttpRequest({mozSystem:true});

What makes difference is 'mozSystem'. In another ticket #13394 someone proposed setting it via xhrFields however mozSystem is read-only and can not be set once XMLHttpRequest object is created. It can be set only on creation:

https://developer.mozilla.org/en-US/docs/DOM/XMLHttpRequest

Attachments (0)
Change History (5)

Changed May 07, 2013 01:08PM UTC by jaubourg comment:1

component: unfiledajax
milestone: None1.10/2.0
owner: → jaubourg
priority: undecidedhigh
status: newassigned
type: bugfeature

You can already handle the problem 3 different ways:

1. global override, no condition:

$.ajaxSetup( {
  xhr: function() {
    return new window.XMLHttpRequest( {
      mozSystem: true
    } );
  }
} );

2. local override, simple condition:

$.ajaxPrefilter( function( options ) {
  if ( options.firefoxOS ) {
    options.xhr = function() {
      return new window.XMLHttpRequest( {
        mozSystem: true
      } );
    }
  }
} );

// Then later on

$.ajaxSetup( {
  firefoxOS: true
} );

3. Generic constructor parameter

$.ajaxPrefilter( function( options ) {
  if ( options.xhrConstructParam ) {
    options.xhr = function() {
      return new window.XMLHttpRequest( options.xhrConstructParam );
    }
  }
} );

// Then later on

$.ajaxSetup( {
  xhrConstructParam: {
    mozSystem: true
  }
} );

1. is simpler but cannot be used generically in a project that may run outside of FirefoxOS,

2. is better at isolating FirefoxOS specific code,

3. is to be used for a more generic approach.

Anyway, we should probably consider adding a standard option (as in 3) seeing as the options object param is part of the standard now: http://www.w3.org/TR/XMLHttpRequest/#dom-xmlhttprequest

Changed May 07, 2013 01:09PM UTC by jaubourg comment:2

milestone: 1.10/2.01.11/2.1

Changed December 16, 2013 04:52PM UTC by dmethvin comment:3

milestone: 1.11/2.11.next/2.next

Changed March 01, 2014 10:00PM UTC by dmethvin comment:4

Method 1 seems good enough here? If we're going to add more code we need docs before landing it, and I shudder to think of more docs for ajax.

Changed April 30, 2014 01:37PM UTC by dmethvin comment:5

resolution: → worksforme
status: assignedclosed

Several good solutions were given above so it seems like we can avoid another mechanism and the docs it would require.