wood burning stoves 2.0*
The moose likes HTML, CSS and JavaScript and the fly likes jQuery form submit using Form plugin not working Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "jQuery form submit using Form plugin not working" Watch "jQuery form submit using Form plugin not working" New topic
Author

jQuery form submit using Form plugin not working

Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Hi all,

I'm using the jQuery Form plugin to post the form with id "myForm", but this seems not to be working. The response of the form is an html table generated using jsp tags. But instead of updating the 'innerHTML' of div with id "divToUpdate", i'm just being sent to a new html page where the html table is displayed. I also tried to alert the returned 'data', but noting happens, and again i'm being sent to a new html page with table. What am i doing wrong?



ps. i thought about the possibility that the path to the .js files might not be correct, so i copied both files to the directory where the jsp containing the above code resides and removed the "../js/" from the path, but unfortunately no success.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

The form isn't being instrumented for some reason.

Verify that your ready handler is executing.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Bear Bibeault wrote:The form isn't being instrumented for some reason.

Verify that your ready handler is executing.

The handler is not executing all, i tried alert-ing a message, but noting happens. What could possibly be the reason for this?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

The js files are not being imported.
Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Bear Bibeault wrote:The js files are not being imported.

I have the following directory structure:
/WEB-INF/js
/WEB-INF/jsp

A jsp file inside the directory named 'jsp' contains the javascript i posted earlier. So i thought that i should refer to the files using the path "../js/".
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

Two things:

1) Relative addressing doesn't work in a servlet environment where URLs don't always represent folder paths. Use server-relative addressing always. This is covered in the JSP FAQ.

2) Anything under WEB-INF cannot be directly served. It's a great place for JSPs that are forwarded to from their controller, but you can't put images, JS, or CSS there.
Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Bear Bibeault wrote:Two things:

1) Relative addressing doesn't work in a servlet environment where URLs don't always represent folder paths. Use server-relative addressing always. This is covered in the JSP FAQ.

2) Anything under WEB-INF cannot be directly served. It's a great place for JSPs that are forwarded to from their controller, but you can't put images, JS, or CSS there.

I was not aware of that, thanks for helping out!
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

My pleasure.
Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Hi all,

Since the problem i am facing is closely related to above problem, i decided not to create a new thread but just add it to this one.

I have the following code



The situation is as follows: The result of posting 'myForm1' is a new form called 'myForm2', therefore i cannot use the '$(document).ready()' to attach an event handler to the submission of 'myForm2'. Instead, i use the following approach; when interacting with the newly created 'myForm2' the function 'submitAndUpdate()' will be called, which will try to attach an event handler to the submission of 'myForm2' before actually doing the submit using javascript code. The problem i run into is that the event handler is not being attached but the submit is executed, therefore instead of updating 'divToUpdate', i am being forwarded to a new page where the result of the submit is being displayed.
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
All you need to do is after you add the second form with html(), call the ajaxForm on it like you would in onready. Seems pretty straightforward.

Eric
Art Vandelay
Ranch Hand

Joined: Dec 27, 2009
Posts: 49
Eric Pascarello wrote:All you need to do is after you add the second form with html(), call the ajaxForm on it like you would in onready. Seems pretty straightforward.

Eric


Do you mean like this?


This will probably sound very stupid, but why do i need to call '.ajaxForm()' on a form after i have set an event handler to take care of ajax form submission using the same call? What's the point of the call after having set the event handler?
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
You were saying you were adding the form2 after the ready fired so you could not attach it correct? I was saying to do it when you added the form to the page.

I really think we should start a new topic.

Create a new thread and we can talk about it in there.

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60785
    
  65

In the future, please start a new topic for new questions. Keeps things neater.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: jQuery form submit using Form plugin not working
 
Similar Threads
Getting duplicate values on the onChange event of dropdown list
Submit dynamically created form using jQuery Form plugin
Struts 2 / Tiles / Tiny MCE
jQueryForm() / jQuerySubmit issue
Struts action mappings not working correctly