I have a page that needs to open several modalities, so as not to compromise on loading the page I decided to call the modal only when the user requested it. I did the following AJAX function:
function loadModal(modalPage, modalBox){
$.ajax({
url: "/modals/" + modalPage,
success: function(data){
$("#" + modalBox + " .modal-body").html(data);
},
beforeSend: function(){
$("#" + modalBox + " .modal-body").html("<img src='/images/loading.gif'> Carregando...");
},
error: function(){
$("#" + modalBox + " .modal-body").html("Ocorreu uma erro!");
}
});
}
So far so good, I can call any page with this function, but the problem is that there are php variables that need to be considered, such as user_id
(which comes from a GET), after I get this id
I do several treatments like searching for the user, translating some dates, calling some user related tables. This is on the main page, but I need this information to go to modal too efficiently. I already thought about passing user_id
by GET method in AJAX, and copying all that treatment I do on the main page. How to make modal read variables without having to do this? Or do I need to do this? The way I did it, is it the most recommended?