javascript code to save a txt file

后端 未结 6 1115
走了就别回头了
走了就别回头了 2021-01-06 12:50

can any body tell me how i create a .txt file using javascript which is browser compatable too.

and after creating the file it gives the save as diaglog box so that

6条回答
  •  孤街浪徒
    2021-01-06 13:26

    you need to send the data to the server and then offer a link to download it. Here's a terrible example with jquery and php just to give you basic idea.

    $.ajax({
        type: "post",
        url: "ajax.php",
        data: {
            type: "save",
            text: "this is some text you want to send"
        },
        dataType: "json",
        success: function(data){
            window.open(data["url"]);
        }
    });
    

    ajax.php

     "link",
                "url" => "http://yourserver.com/{$name}"
            ));
        }
    
    ?>
    

提交回复
热议问题