CreateJS / PreloadJS

PreloadJS makes preloading assets & getting aggregate progress events easier in JavaScript. It uses XHR2 when available, and falls back to tag-based loading when not.
http://createjs.com/
MIT License
2.88k stars 764 forks source link

Posting data failing #252

Closed benjajim closed 4 years ago

benjajim commented 6 years ago

There seems to be a bug when running the following code:

    var manifest = [
        {
            src: 'http://myserver/index.php', 
            id: "posttest", 
            data: "rawData", 
            method:createjs.Methods.POST, 
            headers: {"X-My-Header":"foo"}
        }
    ];

    preload = new createjs.LoadQueue(false);
    preload.on("complete", handleComplete);
    preload.on("fileload", handleFileLoad);

    preload.loadManifest(manifest, true);

If I'm right, it doesn't appear to handle the "data" property anywhere. If you send using "values" you get some success, but there's definitely something wrong, or I'm reading it wrong.

The code where I believe it should be handled is in
XHRRequest._createXHR() and XHRRequest.load()

If I'm missing something, please let me know.

Thanks!

tobyski commented 4 years ago

I just ran into this and couldn't find a way of sending over 'data' with the currently available version of PreloadJS that ships with Animate 2020, unless I am missing something it seems to be completely ignored and only works with values (I did see that maybe data is supposed to be used in conjunction with auth but I need a way to send over raw data with the load).

Around line 209 of preloadjs_net_XHRRequest.js you can modify the try-catch to make use of data in this way:

try { 
    if(this._item.values) {
        this._request.send(createjs.URLUtils.formatQueryString(this._item.values)) 
    } 
    else if(this._item.data) { 
        this._request.send(this._item.data) 
    } 
    else { 
        this._request.send() 
    } 
} 
catch(a) {
    this.dispatchEvent(new createjs.ErrorEvent("XHR_SEND",null,a))
}

This at least works for me in my specific use-case, I'm just adding it here since this came up when I was searching for this perceived 'issue', I'm in no way suggesting this is an appropriate 'fix' :D

Edit: This doesn't do anything with 'data', it assumes the data is stringified/serialized already by you.

benjajim commented 4 years ago

Thanks! I must've coded around it at the time. I appreciate the post! All the best