0
I have a page that I need to open several modals, not to compromise in loading the page I decided to call the modals 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 with this function any page, but the problem is that there are variables php that need to be considered, as user_id
(that comes from a GET), after catching that id
I do various treatments like search the user, translate dates, call more user related tables. This is on the main page, but I need this information to also pass to modal efficiently. I’ve already thought about passing the user_id
by GET method in AJAX, and copy 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 it? The way I did, it’s the most recommended?
Can you return a Json with the php information where the ajax was encoded? I believe you can build a Json with everything you need and in return you can get the values you need.
– Rodrigo Tognin