Skip to content

JSON Downloading #4

@thewabbit

Description

@thewabbit

Hey, just wondering why its been set to POST to another server/webpage to return the JSON? Couldn't this be achieved in the JS like such:

            onSaveItemToFileClicked: function (e) {

                var sessionString = "",
                    fileName = "",
                    sessions = [];

                fileName = string.substitute(this.config.fileNameTplForSession, e.item);

                sessions.push(e.item);
                sessionString = JSON.stringify(sessions);

                this.downloadObjectAsJson(sessionString, fileName)

                // // update form values
                // this.saveToFileName.value = fileName;
                // this.saveToFileContent.value = sessionString;

                // // trigger the post to server side
                // this.saveToFileForm.submit();

                console.log('SaveSession :: onSaveItemToFileClicked :: end');
            },

            downloadObjectAsJson: function(exportObj, exportName){
                var dataStr = "data:text/json;charset=utf-8," + encodeURIComponent(JSON.stringify(exportObj));
                var downloadAnchorNode = document.createElement('a');
                downloadAnchorNode.setAttribute("href",     dataStr);
                downloadAnchorNode.setAttribute("download", exportName);
                downloadAnchorNode.click();
                downloadAnchorNode.remove();
            },

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions