I am trying to use ajax to refresh a page fragment located in the same JSP. I have been told I can do this by placing my fragment within div tags. Here is what I have now, am I on the right track? Thanks.
The issues I can see on a very quick inspection are that your ready state function is not correctly testing for successful completion (doesn't check status code), and while you say that you want to load an HTML fragment with the response, you are instead loading it as the value of a form element.
Is this just code you found somewhere, or did you write it?
Originally posted by Adam J Smith: my jsp with the table in it is throwing a NullPointerException. I think the attributes I am setting in my servlet are not making it to my table jsp. Do I possibly need to pass my request to the jsp called by my ajax? If I do how would I do that?
Once once the server, an Ajax request is like any other. Your servlets and JSP don't know and don't care whether it's an Ajax request or not. So you'd go about writing your code just like any "normal" request, and debug it in the same way.
If you are forwarding from the servlet to the JSP just as you would in any other request, any scoped variables you set on the request will propagate to the JSP (just like normal).
I recommend reading this article in order to get your mind wrapped around Ajax and how it works.
Using jQuery, all that Ajax code needed to grab some content from the server and stuff it into a target element on the page condenses down into: