jQuery problem
Moderator: General Moderators
jQuery problem
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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: jQuery problem
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
I've used jQuery.ajax without problem so I guess the problem is with your implementation
Re: jQuery problem
That's a classicI make some webs 2.0
Re: jQuery problem
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.
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.
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: jQuery problem
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.
Just copy & paste your jQuery code here.
Re: jQuery problem
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>
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>
- Chris Corbyn
- Breakbeat Nuttzer
- Posts: 13098
- Joined: Wed Mar 24, 2004 7:57 am
- Location: Melbourne, Australia
Re: jQuery problem
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.
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
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.
Do you have anysite using $.ajax to load pages, Chris ? Can I visit it ?
Thanks for your reply.
Re: jQuery problem
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.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.
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
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% ...Chalks wrote: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.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.
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.
I have change my code:
Every <a> tag before:
Code: Select all
<a href="abc.php" name="ajax" target="#maincontent">
Code: Select all
<a href="#abc.php" name="ajax" target="#maincontent">
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;
});
});
Really Thanks.
Re: jQuery problem
jQuery = Javascript = Client Side.
Moving to the appropriate forum.
Moving to the appropriate forum.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.