Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

jQuery UI Widget issue

 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Guys,

I have a page rendered using jQuery UI. I have a next button and on click of the next button, I load a div element whose contents are rendered using a jsp. But what I have noticed is that after a couple of clicks of the next button, I get to see the following error:


Is this a bug with jQuery?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm investigating the potential cause to this issue. Following is the snippet that submits the form:



My question is, since this is called on document ready, is this return false alone enough to prevent the form being submitted again and again?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you observed the Ajax and request behavior using tools such as FireBug and HttpFox?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Every click of the next button sends 2 requests to the server. From where is the second request originating?
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
My guess is that the else part could be playing foul?
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64967
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Without details, I can't guess.
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just a side note, the $(this) over and over again is BAD practice. Each time $(this) is called it has to create a new instance and do the lookup. Store it once into a variable and reuse it.

Eric
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think the problem here is this line



fadeOut is NOT synchronous, it has a callback.

Eric
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for the suggestions. I have already removed the fadeIn and fadeOut calls. Will modify the function to avoid calling $(this) repetitively.
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I guess here the form is submitted twice for each click. Once when the next button is clicked and then after page load. Is there a way to avoid the second submit?
 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you saying the whole page is submitting?

preventDefault()

Eric
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Are you saying the whole page is submitting?

preventDefault()

Eric


I'm not sure if it is the whole page, but I get to see the alert message being called twice for each click of the next button.

 
Eric Pascarello
author
Rancher
Posts: 15385
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Do you realize that this line:



is in the wrong location?

If the code is being called twice, are you sure somehow it is not being hooked up twice. Do you have an invalid html markup with two nested forms?

Eric
 
Joe Harry
Ranch Hand
Posts: 10124
3
Eclipse IDE Mac PPC Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Eric Pascarello wrote:Do you realize that this line:



is in the wrong location?

If the code is being called twice, are you sure somehow it is not being hooked up twice. Do you have an invalid html markup with two nested forms?

Eric


Shoudn't in be inside the document ready function? I have two different forms on my page with different id and based on the id, I determine which div to update.

I chcked my rendered HTML amd I do not see any nested forms.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic