0

I'm attempting this tutorial - http://mobile.tutsplus.com/tutorials/mobile-web-apps/jquery-mobile-forms/ to get a jQuery form up and running. I'm using jsp instead of php, so instead of requestProcessor.php(as specified by tutorial) I have requestProcessor.jsp

Here is my requestProcessor.jsp -

<%
out.print("FTREIK12345678");
%>

Here is the jQuery im using to submit the form -

$.post("/forms/requestProcessor.jsp", form1Var.serialize(), function(data){
  confirmationVar.text(data);
  hideContentTransition();
  showConfirmation();
});    

I dont seem to be receiving any data back from the server. I dont know what im doing wrong.

Any help is very much appreciated.

user701254
  • 3,935
  • 7
  • 42
  • 53
  • What is confirmationVar, are you sure that it is a jQuery-object that contains at least 1 element-node ? – Dr.Molle May 16 '11 at 12:35

1 Answers1

0

If you don't get anything then it simply means that the URL is plain wrong. To be more sure, you should use Firebug or Fiddler to track HTTP requests/responses. If you see a 404 being logged when you execute the jQuery $.post(), then the URL is definitely wrong.

The way as you've definied the URL, with a starting leading slash, makes it relative to the domain root. So if you have the JSP page with the form opened by for example http://example.com/context/page.jsp, then this URL will absolutely point to http://example.com/forms/requestProcessor.jsp. You need to ensure that this URL is correct. I.e. you should be able to open it as well by simply entering it in browser address bar. However, if the URL is actually on http://example.com/context/forms/requestProcessor.jsp, then you need to change the $.post() URL to forms/requestProcessor.jsp or to /context/forms/requestProcessor.jsp.


Unrelated to the concrete problem: a JSP is essentially the wrong tool for the job. It's intented as a view template for HTML, not for other content types. You may find this post useful to learn how to use a servlet to handle ajax requests.

Community
  • 1
  • 1
BalusC
  • 1,082,665
  • 372
  • 3,610
  • 3,555