我必须通过POST传递数据,在PHP中的函数,问题是他们不检索数据。
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) {
}
在PHP控制器侧
if ($_GET["action"] == "copiar_archivo"){
echo json_encode($controlador-> copiar_archivo($_POST["origen"], $_POST["destino"]));
}
在PHP函数,模型。
function copiar_archivo($path_o, $path_dest){
//some code
}
我不知道我是否清楚。
I don't know if i am clear.
您阿贾克斯code应该重建是这样的:(注意:该对象被发送的数据参数)
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) {
}
)}
此外,在你的PHP,你并不需要使用 GET
因为你的Ajax是发送 POST
请求。从而使 GET ['行动']
无关。
Also, in your PHP, you don't need to use GET
since your ajax is sending a POST
request. Thus making GET['action']
irrelevant.
上一篇:jQuery的事件不触发动态创建的元素元素、事件、动态、jQuery
下一篇:使用waitForKeyElements,是有可能prevent被显示的关键要素,并只显示它之后它是由我的code修改?是有、它是、只显示、由我