Code Monkey home page Code Monkey logo

xmlhttprequest's People

Contributors

bendingbender avatar elerch avatar heldermagalhaes avatar ilinsky avatar marijn avatar scotmcc avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

xmlhttprequest's Issues

Feature request: Add timeout support

The XMLHttpRequest level 2 specification recently added timeout support, AFAIK by "inheriting" the the feature introduced in IE8. Nightly Gecko builds already support this feature, which will likely be shipped in Firefox 13, so it would be great to have this feature available in a cross-browser way:

  • Try to detect the timeout attribute and/or ontimeout event and use the native feature, when available;
  • Fallback to a script implementation on non-supporting environments.

window.document.all is not good enough to detect IE

In order to work around and IE memory leak issue, the following code tries to detect whether the browser is IE:

var bIE     = window.document.all && !window.opera;

window.document.all exists in various versions of Firefox and therefore isn't a good enough way to determine whether the browser is IE. Later the bIE variable is checked and an event handler is registered onunload:

window.attachEvent("onunload", fOnUnload);

which of course fails for Firefox that lacks attachEvent (and doesn't need ant memory leak workaround).

rewriting ajax requests

I'm trying to use xmlhttprequest.js to intercept an ajax request and request a different url instead. The code all looks correct, but it's failing silently with no hints in the developer console. Here is a live preview along with the code:

http://embed.plnkr.co/5Vpdohf69anQlUutHl7Y/preview

Am I doing something wrong, or is this just not possible?

Thanks in advance for any tips.

fGetDocument error for IE

Using xmlHtjp = new window.XMLHttpRequest()
...
if (xmlHttp.readyState === XMLHttpRequest.DONE) {
if (xmlHttp.status === 200) {
xml = xmlHttp.responseXML.documentElement;

is failing on IE6, 7, 8, 9 [all the versions I have current access to] . Traced to fGetDocument. The check for errors in the document needs to be something like:
if ((bIE && oDocument.parseError && oDocument.parseError.errorCode !== 0) || ...
instead of
if ((bIE && oDocument.parseError !== 0) || ...

Has no-one been using responseXML with IE? I checked back to the earliest version on github, and it has the same incorrect parseError test. I tested my fix against IE6, 7, 8, 9. With that bIE in the check, nothing else should get affected.

Timestamp in the fake readystatechange event is wrong

The line 474 in the code is wrong, as below:

// Fake event
oRequest.dispatchEvent({
    'type': "readystatechange",
    'bubbles': false,
    'cancelable': false,
    'timeStamp': new Date + 0
});

new Date + 0 will results a string with something like "Tue Jun 11 2013 13:07:09 GMT+0800 (HKT)0", by the specification, it should be a timestamp in long type. So it should be:

// Fake event
oRequest.dispatchEvent({
    'type': "readystatechange",
    'bubbles': false,
    'cancelable': false,
    'timeStamp': new Date().getTime()
});

very slow load time request in chrome

I have trouble with loading big datasets (28mb json, zipped 645kb) in chrome with OpenLayers. I debugged the code and the problem appeared to be in xmlhttprequest.

Function: "cXMLHttpRequest.prototype.open"
Inner function: "this._object.onreadystatechange = function() {"

This function is accessed alot of times in chrome while handling the request. The total request takes long because the call:
"fSynchronizeValues(oRequest);" seems to be expensive.

I replaced the first call to "fSynchronizeValues" with the following code:
if (oRequest._object.readyState===4 && oRequest._object.status === 200) {
fSynchronizeValues(oRequest);
}

The total request is much faster now. From 2 minutes to just a few seconds....
Im not sure though if this is the correct solution

Regards Mark

send(undefined) and send("") fails.

I'm loading test JSON data from a text file on a local web server (using IE) and thus don't need to send anything. Normally I send undefined or "", and it works using the native xmlHttpRequest object, but not with your wrapper.

According to the specification I found (http://xhr.spec.whatwg.org/#the-send()-method): "If data is null, do not include a request entity body and go to the next step." However, the data is not null when it's undefined or empty, and thus most browsers I've tested will send an empty request in these cases, AND return the response (or file in this case).

Using xmlhttprequest in jsonrpcjs

Hi,

i wish to use this library in another project. The project is located at:

https://github.com/gimmi/jsonrpcjs

and it's licensed as Apache. I can change the license to LGPL without problem.

Another thing that i wish to do is that my intentions is to use xmlhttprequest internally, but the unmodified version of the code replace XmlHttpRequest in the global scope.

Can you update the code so that by default XmlHttpRequest is untouched?
Can i include your sources in jsonrpcjs lib?

Thanks!

Add support for upload property

The XMLHttpRequestUpload object that is accessible through the upload property is not accessible through the new XHR object. This property, along with the other missing ones, should be surfaced so it doesn't break existing functionality of the original XHR.

IE fGetDocument Bug

The following function has a bug in it:

function fGetDocument(oRequest) {
    var oDocument = oRequest.responseXML;
    var sResponse = oRequest.responseText;
    // Try parsing responseText
    if (bIE && sResponse && oDocument && !oDocument.documentElement && oRequest.getResponseHeader("Content-Type").match(/[^\/]+\/[^\+]+\+xml/)) {
        oDocument = new window.ActiveXObject("Microsoft.XMLDOM");
        oDocument.async       = false;
        oDocument.validateOnParse = false;
        oDocument.loadXML(sResponse);
    }

    // Check if there is no error in document
    if (oDocument){
        if ((bIE && oDocument.parseError != 0) || !oDocument.documentElement || (oDocument.documentElement && oDocument.documentElement.tagName == "parsererror")) {
            return null;
        }
    }
    return oDocument;
}

Instead of

if ((bIE && oDocument.parseError != 0) || !oDocument.documentElement || (oDocument.documentElement &&     oDocument.documentElement.tagName == "parsererror")) {'''

it should be

if (if ((bIE && oDocument.parseError.errorCode  != 0)'''

Where it should be checking the parseError.errorCode property to see if there is an error NOT the object.

Infinite loop upon creation of new XMLHttpRequest Object

The changes introduced in commit #8f1e7b940a476b0964483392a11005dc313dd3ff lead to an infinite loop between lines 33 and 27 by simply executing:

new XMLHttpRequest();

I suppose that this code will actually work if XHR object was first replaced by this library and after that replaced by yet another library but the way it is right now, the code simply doesn't work if this library is used stand-alone. Simply reverting the changes introduced by the above commit fixes the problems, but supposedly negates the effect intended by the original committer. Furthermore, the author forgot to replace the check in line 38

if (bGecko && oXMLHttpRequest.wrapped) {
    cXMLHttpRequest.wrapped = window.XMLHttpRequest.wrapped;
}

because oXMLHttpRequest variable doesn't exist any more after the commit.

Support for other HTTP methods

I was wondering if it would make sense to update the send method to check for the HTTP method.
In case the requested method is not supported by the browser we could add the X-HTTP-Method-Override header which seems to be common these days.
Would you be open for such a modification or should it perhaps be added as syntactic sugar to a wrapper object...?

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.