S
S
Sergey Sorokin2018-03-22 15:49:52
JavaScript
Sergey Sorokin, 2018-03-22 15:49:52

How to save a file from a site as a picture?

I found a js script on the Internet, which makes it possible to fill out a template form, later save it as a picture.

// отправляем на рендеринг
    $.ajax({
        type: "POST",
        url: $('form').attr('action'),
        data: data
    }).done(function(result) {
        location.href = 'http://адрессайта/downloader.php?filename='+result;
    })
    .fail(function(msg){
        //alert(msg);
        console.log(msg);
    });

But the downloader.php file itself is missing
Tell me exactly how the file saving works

Answer the question

In order to leave comments, you need to log in

1 answer(s)
I
ilyale, 2018-03-23
@ilyale

Judging by the code, jQuery is used.
Your script sends data via an asynchronous HTTP GET request ( see the docs , the GET method is used by default) to the address specified in the form's HTML action attribute . The response from the script that processed your request is placed in the result variable , and then passed to the response processing function, which redirects (redirects) the client browser to the downloader.php script

function(result) {
        location.href = 'http://адрессайта/downloader.php?filename='+result;
    }

This script, apparently, simply displays the response from the server, i.e. from the script that processed the form data.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question