3
I’m in trouble, which begs a big question.
I’m developing a website that has a standard structure, which makes GET calls on Jquery
to search for new HTML pages for certain parts of the page.
Example: I click on a link and the page change is done without the page reloading.
But here’s the problem. The pages added later by Ajax, which has some elements that use code in JavaScript
, as slides, charts, maps, among other elements, are added correctly, but these cited elements do not work, only if they are incorporated right at the beginning of the site (as soon as the site is loaded).
What should I do to ensure that this does not occur and that these elements function correctly?
Welcome to Sopt, good first, Check your code? we can’t guess your problem. beware of informality when posting, no GRIP code, it can copy, work, generate errors on the console etc.
– Isvaldo Fernandes
Thanks Isvaldo! Actually, the problem is much more theoretical. Actually, there’s no way I can put any of this here for you, because this is the whole site, with really big codes. I wonder if, in theory, this should happen, by the fact of pulling a page later and all.
– René Gustavo
@Renégustavo your problem is in your Jquery, which only takes the existing items on the screen, and when you make the Ajax request, it does not bother to put the events and functions in your new code. For example
$( "#target" ).click(function() {
 alert( "Handler for .click() called." );
});
this is a standard click evendo, but if you use your Ajax it will not work. You would have to use:$('#salvaHorarioAvulso').on('click', function () {
 CriaHorarioAvulso();
 });
this way Jquery always keeps listening and seeing the page codes.– Tiedt Tech
@Marlontiedt, I get it and I know what it’s like. This has to do with the question of functions that load maps, graphs and other things, at the time of loading, without any user action?
– René Gustavo