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

JQuery: Problem with $(this).find('input'). serialize()

 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I have following code in Html,Js and JSP followed by weird out put of jsp, can some kindly let me know whats wrong with any of the file?
====== ===== ============ ======== HTML ========= ======== ========

====== ====== ======= ======= ===== JS ======= ======= ===========

===== ==== ========= ======= ====== JSP ===== ==== ========== ======



========== ====== ===========

out put ======================


If i uncomment js code in file then the alerts show me correct names of input field.


-Praful
[ April 21, 2008: Message edited by: Praful Thakare ]
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
okay,did some rnd and found the pattern of this weird behavior, serialize method is converting each char of parameter and value in to one separate request parameter value pair. i kept only one input with name term and value as praful, so instead of passing it as term=praful it is passed as

Bear, what are your thoughts?

-P
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Your issue is with the data parameter that you are passing to the load() method:



That param is expected to be an object hash of the parameters to send with the request. The serialize() method returns a query string of the params (which is useful when setting the post body of request, but not here), so the string is being parsed into its separate characters for sending as the prams. Not what you want.

You want to use the serializeArray() method which returns an object hash suitable for use with load():
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You The Man Bear, its working now.

It also runs without any method only difference in this case it also send submit button as request parameter and in case of serializeArray it does not send submit button.

Also, does load method not use Post for sending form data?


-P
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If I recall correctly, load() always uses a GET.
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ah, okay..i am exploring the jQuery pulgins now, may be there is better way to submit form for Ajax request.

-P
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64982
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Check out the official jQuery Form Plugin.

It makes easy to instrument a form to submit itself through Ajax.

For example:



will automatically cause the form to submit itself as an Ajax request when submitted.
 
Praful Thakare
Ranch Hand
Posts: 642
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
awesome !!! thanks much, I am so glad I followed your suggestion to choose JQuery, enjoying exploring it.

-P
[ April 23, 2008: Message edited by: Praful Thakare ]
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic