1

I have to pass data through POST, to a function in PHP, the problem is they don't retrieve the data.

var jsonText = JSON.stringify(origen);
var jsonTextDestino = JSON.stringify(destino);
$.ajax({
    type: "POST",
    url:"/lie/controlador/manejo_de_archivos/controlador.php?action=copiar_archivo",
    data: "origen=" + jsonText + "&destino=" + jsonTextDestino ,
    async: false,
    dataType: "json",
    success: function (jsondata) {
    }

controller Side in PHP

if ($_GET["action"] == "copiar_archivo"){
    echo json_encode($controlador-> copiar_archivo($_POST["origen"],    $_POST["destino"]));
}

function in PHP, model.

function copiar_archivo($path_o, $path_dest){
    //some code
}

I don't know if i am clear.

1
  • Why do you mix GET with POST? Commented Aug 28, 2015 at 15:51

2 Answers 2

2

your ajax code should be rebuilt this way: (Notice the object being sent as your data parameters)

var my_object = {"origen": origen, "destino":destino};
$.ajax({
    type: "POST",
    url:"/lie/controlador/manejo_de_archivos/controlador.php?action=copiar_archivo",
    data: my_object ,
    async: false,
    dataType: "json",
    success: function (jsondata) {
    }
)}

Also, in your PHP, you don't need to use GET since your ajax is sending a POST request. Thus making GET['action'] irrelevant.

Sign up to request clarification or add additional context in comments.

Comments

1
var form = new FormData();
form.append("key1", "val1");
form.append("key2", "val2");

var settings = {
  "async": true,
  "crossDomain": true,
  "url": "http://test.com/php.php",
  "method": "POST",
  "headers": {},
  "processData": false,
  "contentType": false,
  "mimeType": "multipart/form-data",
  "data": form
}

$.ajax(settings).done(function (response) {
  console.log(response);
});

try something like this code m8 with should help you out

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.