Hello I have the following ajax functions which are directed to the same file:
$.ajax({
url: "url.php",
method: "GET",
async: false,
dataType: "json",
success: function(respuesta) {
//Accion 1
}
});
$.ajax({
url: "url.php",
method: "GET",
async: false,
dataType: "json",
success: function(respuesta) {
//Accion diferente al otro AJAX
}
});
File "url.php" where the AJAX functions arrive
<?php
#CLASES
#**********************************************************************
class Ajax{
#EJECUTA LA FUNCION 1
#******************************************************************
public function accion1(){
//Se ejecuta lo que quiero en la funcion 1
}
#EJECUTA LA FUNCION 2
#******************************************************************
public function accion2(){
//Se ejecuta lo que quiero en la funcion 2
}
}
#OBJETOS
#************************************************************************
$a = new Ajax();
$a -> accion1();
$b = new Ajax();
$b -> accion2();
?>
How can I difference so that the first AJAX function goes into action1 and the other one into action2?
Beforehand thank you very much.
As far as I know you can't directly reference a PHP function using AJAX. However, what you can do is pass a parameter via AJAX with the parameter
data
:And from the PHP check said parameter and execute one function or another depending on the value that arrives: