Page 1 of 1
jQuery problem
Posted: Mon Dec 08, 2008 2:09 am
by htdung
Dear all,
I'm a newbie in jQuery. I make some webs 2.0, included jQuery library and used $.ajax to send the request to server. I got a trouble : the cpu usage go high each time I click on the links which called the $.ajax, beside that the browsers(IE, FF3) spent high memory too. Was there anybody solve this problem ? Help.
Thank you all.
Re: jQuery problem
Posted: Mon Dec 08, 2008 2:31 am
by Chris Corbyn
You're really going to have to post some code. I can't even take a stab in the dark without seeing the code
I've used jQuery.ajax without problem so I guess the problem is with your implementation

Re: jQuery problem
Posted: Mon Dec 08, 2008 3:39 am
by Eran
I make some webs 2.0
That's a classic
Re: jQuery problem
Posted: Mon Dec 08, 2008 3:44 am
by htdung
Dear Chris,
This is my site
http://gtecgroup.nganphuongco.com/index.php.
You should open the task manager to see the problem I talked about. After each of click on the link in topmenu, the cpu usage go high and turn back to 0%. And, that number is higher and higher after I click. I don't know what is the issue.
Thanks for your help.
Re: jQuery problem
Posted: Mon Dec 08, 2008 3:56 am
by Chris Corbyn
I went to the site, couldn't see the word "Task Manager" anywhere, so I left. You really have to post the code here. People don't like running around much
Just copy & paste your jQuery code here.
Re: jQuery problem
Posted: Mon Dec 08, 2008 4:32 am
by htdung
I mean you open the Task Manager of Window by click right mouse on your task bar and choose Task Manager . You can see the process iexplorer.exe . Your can set the Task Manager always ontop and click on the link in my site. You can see the CPU usage goes high each click.
Here is my code:
<script type="text/javascript">
function link(url,target){
$(target).html('<img src="templates/images/loading.gif">');
$.ajax({
url: url,
cache:false,
error:function(html){
$(target).html('The page is not exists !');
return false;
},
success: function(html){
$(target).html(html);
return false;
}
});
return false;
}
$(document).ready(function() {
$('a[name=ajax]').click(function(){
link(this.href,this.target);
return false;
});
link("home.php","#maincontent");
});
</script>
Re: jQuery problem
Posted: Mon Dec 08, 2008 6:38 am
by Chris Corbyn
CPU usage will always rise for a brief moment when the window redraws itself. I'm using Firefox on a mac and I don't see anything out of the ordinary
What version of Internet Explorer are you using and what are the specs of your computer?
On a 2GHz Core 2 Duo with 2GB DDR3 RAM I see a brief moment of around 25% CPU use when I click the link, then it falls back down to around 10% (just idle) within a fraction of a second.
Re: jQuery problem
Posted: Tue Dec 09, 2008 9:23 pm
by htdung
I don't agree with you. If the configuration of the computer is slow. The webpage will be slowly loaded. When you click on the links, they will be loaded with the same speed. I use AMD CPU Turion Dual Core 1.8GH, 1GB DDR2 Bus 800 MHz. But the website can get my computer slow down because it spend so much memory.
Do you have anysite using $.ajax to load pages, Chris ? Can I visit it ?
Thanks for your reply.
Re: jQuery problem
Posted: Fri Dec 12, 2008 8:50 am
by Chalks
htdung wrote:I use AMD CPU Turion Dual Core 1.8GH, 1GB DDR2 Bus 800 MHz. But the website can get my computer slow down because it spend so much memory.
Honestly, that's a pretty slow computer, especially if you're running Vista on top of it. If you're just running XP, it's still pretty slow. If you have a bunch of programs running at startup, that will slow it even more.
Also, not only does your computer speed influence how fast the website loads, your internet speed does too. Additionally, the server speed makes a difference as well (at least in the case of AJAX). So if you're using a cheap/free server, have slow internet, and your computer is slow... of course it will appear as if ajax is running extra slow to you.
Re: jQuery problem
Posted: Fri Dec 12, 2008 9:36 pm
by htdung
Chalks wrote:htdung wrote:I use AMD CPU Turion Dual Core 1.8GH, 1GB DDR2 Bus 800 MHz. But the website can get my computer slow down because it spend so much memory.
Honestly, that's a pretty slow computer, especially if you're running Vista on top of it. If you're just running XP, it's still pretty slow. If you have a bunch of programs running at startup, that will slow it even more.
Also, not only does your computer speed influence how fast the website loads, your internet speed does too. Additionally, the server speed makes a difference as well (at least in the case of AJAX). So if you're using a cheap/free server, have slow internet, and your computer is slow... of course it will appear as if ajax is running extra slow to you.
Maybe my Eng is so pure, so all of you missed my mean. Althought your computers is slow or high configuration. I think the speed $.ajax send request to server is the same. My problem is that every time I click on the link the CPU usage get higher: 5% , 11% ,18%, 38% , 44% ...
I have change my code:
Every <a> tag before:
Code: Select all
<a href="abc.php" name="ajax" target="#maincontent">
Now:
Code: Select all
<a href="#abc.php" name="ajax" target="#maincontent">
And the JQuery code now:
Code: Select all
var currentAnchor = '';
$(document).ready(function(){
$('a[name=ajax]').click(function(){
target = this.target;
if (currentAnchor!=document.location.hash){
currentAnchor = this.href.substring(this.href.indexOf('#')+1,this.href.length);
query = "";
}
$.ajax({
url: currentAnchor,
error: function (){
$(target).html('The page is not existed !');
},
success: function(data){
$(target).html(data);
}
});
return false;
});
});
Now my website is OK. I can click how many time on the link I wanna. The CPU usage is normal, the memory doesn't get higher. Is there anybody knows what my mistake before ? Tell me pls.
Really Thanks.
Re: jQuery problem
Posted: Mon Dec 15, 2008 5:07 pm
by pickle
jQuery = Javascript = Client Side.
Moving to the appropriate forum.