Does anyone know why in php you can directly access the variables sent by ajax inside an object without using the function json_decode () of php ?. This is the function that sends the value "value":
function mi_funcion() {
var valor = "mi_valor";
$.ajax({
url: "mi_archivo.php",
type: "POST",
async: true,
//data: "valor="+valor,
data: {"valor": valor},
dataType: "json",
success: function(respuesta) {
$("#mi_div").text(respuesta["valor"]);
},
error: function() {
$("#mi_div").text("Error");
},
timeout: 60000
});
}
And this is the php part:
<?php
$resultado = array();
$resultado["valor"] = $_REQUEST["valor"];
echo json_encode($resultado);
?>
PS: The above works well, so my question is why it is accessed in the same way in php for the following two cases: 1. data: {"mtdo": mtdo}, and 2. data: " mtdo="+ mtdo, If in one case it is an object and in the other it is a chain.