0
I’m making a system GED here for the company where I work (very simple, just to organize better).
I’m developing the screens first, then connect with the comic and make things work.
I have a menu that is left with the links to navigate between the pages. On the right I insert the contents of the pages into a DIV called #conteudo
, for this I am using the function load()
jQuery. As below:
// Carrega o conteúdo das páginas dentro da div#conteudo
$('.carrega_pagina').click( function(){
var href = $(this).attr('href'); // pega o valor do atributo href da âncora clicada
$('#conteudo').load(href);
return false;
});
This has worked well, however, by clicking on the links 8-10 times or more, the requested screen takes time to appear (it is as if the browser was crashing), in addition, the browser even consumes up to 70% of the CPU when I request a page (remembering that all this only occurs after browsing several times between the pages, when I give a refresh on the page everything goes back to normal).
I wanted to know if there is a better way to insert the content of the other pages in this DIV.
You’re probably carrying one
javascript
which adds the function to the menu items. As more clicks you make, but functions you will add to the items and more requests these items will make. The ideal is to use a simple request (can be$.GET
) and only load what you need. (No JS already added).– Valdeir Psr
Try to use
html()
in place ofload()
– adventistaam
@Valdeirpsr, that’s exactly what’s going on! I put an Alert in the $.ajax Success and saw that every time I click on a link the request is made again and increases...
– Reginaldo Boeke
@Valdeirpsr Could you give me an example of how to do with $.get? Another question, I am inserting my script file together with the pages because I tried to do before without inserting and it did not work the functions I have on the requested pages. Making with $.get even without inserting them again functions will work?
– Reginaldo Boeke