$ ajax with POST to a .php

0

I have a component in Javascript that previously created a file for the user to save it. Now I am changing that functionality so that it is saved when the button is pressed, but it does so on the server. For this I must use code that is not from the client's side, and I am doing it with AJAX. In the function of the button I have defined the AJAX function like this:

$.ajax({
            type: "POST",
            url: "hola.php",
            data: data,
            // contentType: "text/plain"
        })  
            .done (function (data, textStatus, jqXHR) {
                alert("Guardado correctamente" + jqXHR + data +textStatus );    
            })
            .fail(function (jqXHR, textStatus, errorThrown) {
                console.log("La solicitud ha fallado: " + textStatus + errorThrown);
            });

The php what it does is save the contents of the variable that happened to it in a file with fwrite the php itself that runs well, but I have the problem in which the variable does not reach me well, of course I do the $data = $_POST['data'];

EDIT: Ok, I've noticed that the variable data if I pass it like this: {"data": data} yes it is sent well ... I do not know ...

    
asked by Eric Ferrando 14.08.2018 в 14:43
source

0 answers