Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

jquery ajax xml response not coming from jsp

Posted on 2011-02-19
7
Medium Priority
?
1,563 Views
Last Modified: 2012-05-11
     i am calling jsp through jquery ajax method.but the response is not coming.how to get the response which is in xml format?i put log in jsp there value is printing.but the xml response is not coming .

please modify the code if i written wrongly..
                              
                              $.ajax({      
                                    url: "calculate.jsp",
                                    type:"POST",
                                     dataType: "xml",
                                    data:$('#'+frmid).serialize()+'&requestType=AJAX',
                                    success: function(data) {
                                          obj.complete(data);
                                    },
                           
                              });

                                    complete:function(data){
                                          alert($(data))
                                    var firstname = $(data).find("firstname")[0].nodeValue;
                  },


calculate.jsp
*************
String      suppLastName1 = request.getParameter("suppLastName1");
String      a1firstNameTmp = request.getParameter("a1firstNameTmp");
System.out.println("suppLastName1....."+suppLastName1);
       response.setContentType("text/xml");
          response.setHeader("Cache-Control", "no-cache");
          response.getWriter().write("<application><firstname>"+a1firstNameTmp+"</<firstname><lastname>"+suppLastName1+"</<lastname></application>");
0
Comment
Question by:chaitu chaitu
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 34933443
In bold :
+"</<firstname>
+"</<lastname>

corrected :


response.getWriter().write("<application><firstname>"+a1firstNameTmp+"</firstname><lastname>"+suppLastName1+"</lastname></application>");

Open in new window

0
 
LVL 82

Accepted Solution

by:
leakim971 earned 2000 total points
ID: 34935061
work for me :

<%@ page contentType="text/xml" %>
<%@ page import="java.sql.*" %>
<%
	String suppLastName1 = request.getParameter("suppLastName1");
	String a1firstNameTmp = request.getParameter("a1firstNameTmp");
	response.setContentType("text/xml");
	response.setHeader("Cache-Control", "no-cache");
	response.getWriter().write("<application><firstname>"+a1firstNameTmp+"</firstname><lastname>"+suppLastName1+"</lastname></application>");
%>

Open in new window

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript">
	$(document).ready(function() {
		$("input[type='button']").click(function() {
			var frmid = "myform";
			$.ajax({      
				url: "calculate.jsp",
				type:"POST",
				dataType: "xml",
				data:$('#'+frmid).serialize()+'&requestType=AJAX',
				success: function(data) {
					firstname = $("firstname", data).text();
					alert(firstname)
				},		
			});
		});
	});
</script>
</head>
<body>
<input type="button" value="load" />
<form id="myform">
	<input type="text" name="suppLastName1" value="Experts" />
	<input type="text" name="a1firstNameTmp" value="Exchange" />
</form>
</body>
</html>

Open in new window

0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 34940170
i have one clarification regarding normal reloading the page and ajax call.

whatever values entered in the form cannot be re-captured if i click load button in the case of Reload.jsp but if we replace with ajax code and click load button then previously entered values recaptured in the form with re assigning back to form values.

success: function(data) {
                              firstname = $("firstname", data).text();
                              lastname = $("lastname", data).text();
                              alert(firstname)

                  //do i need to re assign like this back to form values or automaticlaly will be re assigned.
                        
                  $("input[name='a1firstNameTmp']").value=firstname
                  $("input[name='suppLastName1']").value=lastname
},



Reload.jsp
***********

<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Document sans nom</title>
<script language="javascript" src="http://code.jquery.com/jquery-1.4.4.min.js"></script>
<script language="javascript">
      $(document).ready(function() {
            $("input[type='button']").click(function() {
                  

                  location.href="Reload.jsp"

            });
      });
</script>
</head>
<body>
<input type="button" value="load" />
<form id="myform">
      <input type="text" name="suppLastName1" value="Experts" />
      <input type="text" name="a1firstNameTmp" value="Exchange" />
</form>
</body>
</html>

0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 82

Expert Comment

by:leakim971
ID: 34940184
?
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 34940296
you didnt understand my doubt??
0
 
LVL 20

Author Comment

by:chaitu chaitu
ID: 34948514
my requirement is it has goto server side once when the session is time out so whatever values entered before session time out should be captured and to reassigned back to form values.

  //do i need to re assign like this back to form values or automaticlaly will be re assigned.
                       
                  $("input[name='a1firstNameTmp']").value=firstname
                  $("input[name='suppLastName1']").value=lastname
0
 
LVL 82

Expert Comment

by:leakim971
ID: 34948600
Just to be sure what you recorded is same as what you're displaying I would choose to re assign
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article discusses how to create an extensible mechanism for linked drop downs.
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

604 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question