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:
Attachments (0)
Change History (5)
Changed May 07, 2013 01:08PM UTC by comment:1
| component: | unfiled → ajax |
|---|---|
| milestone: | None → 1.10/2.0 |
| owner: | → jaubourg |
| priority: | undecided → high |
| status: | new → assigned |
| type: | bug → feature |
Changed May 07, 2013 01:09PM UTC by comment:2
| milestone: | 1.10/2.0 → 1.11/2.1 |
|---|
Changed December 16, 2013 04:52PM UTC by comment:3
| milestone: | 1.11/2.1 → 1.next/2.next |
|---|
Changed March 01, 2014 10:00PM UTC by 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 comment:5
| resolution: | → worksforme |
|---|---|
| status: | assigned → closed |
Several good solutions were given above so it seems like we can avoid another mechanism and the docs it would require.
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