• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

jQuery form submit using Form plugin not working

 
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The form isn't being instrumented for some reason.

Verify that your ready handler is executing.
 
Art Vandelay
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The js files are not being imported.
 
Art Vandelay
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My pleasure.
 
Art Vandelay
Ranch Hand
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 49
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
Posts: 15385
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In the future, please start a new topic for new questions. Keeps things neater.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic