Reputation: 215
Is it possible to find the data that was sent as argument to XMLHttpRequest's send(data) function in its onreadystatechange handler? I assume it must be stored in one of it's properties at that point.
The reason I'm asking is because this callback calls another function which requires said data, but the data is not known until before XHR.send() was called, so I can't just put it into XHR constructor. Right now I have to use a global var for that data, which I wanted to get rid of. Here is the code snippet: https://bpaste.net/show/2150361d3dbe
I'm using XHR to get an image as a blob, so apparently jQuery's Ajax is not an option. All this is being used in a userscript of mine, not on a website, so I don't know, maybe global vars aren't that much of a problem at all.
Upvotes: 0
Views: 197
Reputation: 664548
No, the sent data is not available as a property of the XHR object. It is supposed to be garbage-collectable as soon it is put on the wire.
Depending on how you create the onreadystatechange
callback, the data
variable might still be in scope, so you can directly access it (and pass it to the other function).
Setting the data manually as a property of the respective xhr object is still better than using a global variable.
Upvotes: 1