通过POST通过使用$阿贾克斯多个参数的PHP函数 [英] passing multiple parameters using $.ajax by POST to php function
本文介绍了通过POST通过使用$阿贾克斯多个参数的PHP函数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我必须通过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.
这篇关于通过POST通过使用$阿贾克斯多个参数的PHP函数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文