Create json file using blob

前端 未结 2 1075
無奈伤痛
無奈伤痛 2021-02-19 01:56

I have written json code in string and i want to send it using xmlhttp as .json file. Is it possible to do it with blob?

var cleanScript = {
    \'type\': \'scri         


        
2条回答
  •  再見小時候
    2021-02-19 02:14

    Try something like this

    var cleanScript = {
        'type': 'script',
        'api_key': api_key,
        'data': data,
        'inputs': inputs,
        'timeoutSeconds': timeoutSeconds
    };
    var jsonse = JSON.stringify(cleanScript);
    var blob = new Blob([jsonse], {type: "application/json"});
    var url  = URL.createObjectURL(blob);
    
    var a = document.createElement('a');
    a.href        = url;
    a.download    = "backup.json";
    a.textContent = "Download backup.json";
    
    document.getElementById('json').appendChild(a);
    

提交回复
热议问题