I have a problem using AJAX.
I have created a function to call a function within a PHP class by means of AJAX and at the moment of calling the function, I return a response with a return.
This is my AJAX function, where the php class identifies 'cmd' and interprets it as a function.
function nk_route_get(ModuleUrl, Data = {}, Alert = {}) {
if (Data['cmd']) {
$.ajax({
data: Data,
url: ModuleUrl,
type: 'get',
beforeSend: function () {
},
success: function (response) {
if (response == 1) {
$(".alert").addClass("hidden");
$('#alert-success').removeClass('hidden')
$('#alert-success-text').html("<i class=\"fa fa-check fa-2x\"></i> " + Alert['success']);
$("input").css({"border-color": "#ced4da"});
} else if (response == 2) {
$('#alert-danger').removeClass('hidden')
$('#alert-danger-text').html("<i class=\"fa fa-exclamation-triangle fa-2x\"></i> Ha ocurrido un error, consulte con el administrador.<br>");
} else {
$('#alert-danger').removeClass('hidden')
$('#alert-danger-text').html("<i class=\"fa fa-exclamation-triangle fa-2x\"></i> " + response);
// $("#Alert").html(response);
}
}
});
}
else {
console.warn("No se han mandado los parametros solicitados.")
}
}
This is what I put in my PHP function where I call a function that returns a return.
$html = nk_forms::html("ul",["class"=>'list-group list-group-flush'],nk_forms::html("li",['class'=>'list-group-item'],'asjjhd'));
$Scripts = "$('#Modal-Body').html('{$html}');";
echo "<script>{$Scripts}</script>";;
And this is the function that returns a return.
static function html($Tag,$Attr,$Html){
$HtmlAttr = "";
if (!$Tag || !$Attr || !$Html){
return false;
}
if (is_array($Attr)){
foreach ($Attr as $id => $value ){
$HtmlAttr .= $id . " = '" . "{$value}'";
}
}
$HtmlTag = "<{$Tag} {$HtmlAttr} >{$Html}</{$Tag}>";
return $HtmlTag;
}
The problem with this is that the return cuts off the AJAX response.