• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

calling jsp page using Jquery

 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all,

I have this code snippet where I am passing data to another jsp file. and in Ajax.jsp , my code is . Now when I click on text box in index.jsp, I am getting alert promt saying data has been saved. but when I display Ajax.jsp the value is null. My doubt is , am I really passing data to another jsp ? Am I wrong in code ? Please correct me.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65229
95
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Let's start by cleaning up the basics.

If you are using jQuery, what with: onclick="javascript:getInput()" ? Use jQuery to set up event handling. ALos, never use the javascript: prefix when not using jQuery.

Your JSP does not create valid HTML. Is it supposed to?
 
jazy smith
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Bear,

so what could be the way if I want to use the same two code and want to pass parameter to another jsp using same jquery function. From your reply what I understood is , I have to create event handler. Any help or link you can provide to run this simplest example. ( i want to use same jquery ajax function and want to pass data to another jsp )

thanks in advance,
 
Ganesh Ravi Kumar
Greenhorn
Posts: 17
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Here is the code, that will do..........


<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
<script type="text/javascript" src="js/jquery-1.4.2.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("#click").click(function(){
name=$("input#name").val();
age=$("input#age").val();
$.ajax({
type:"POST",
url:"jsp/pageTwo.jsp",
data:"name="+name+"&age="+age,
success:function(data){
$("#response").html(data);
}
});
});
});
</script>
</head>
<body>
Name: <input type="text" id="name" name="name"><br/><br/>
Age  : <input type="text" id="age" name="age"><br/><br/>
<button id="click">Click Me</button>
<div id="response"></div>
</body>
</html>
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic