dcsimg
AJAX post-back
1 posts in topic
Flat View  Flat View
TOPIC ACTIONS:
 

Posted By:   ranadhir_nag
Posted On:   Sunday, February 18, 2007 11:00 AM

I have a javascript function for a POST request from XMLHttprequest object.The post-back is handled within the decode function of the component which generates the AJAX request. The javascript request looks as follows: function lookup(field) { .... if (window.XMLHttpRequest) { req = new XMLHttpRequest(); } else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); } var formdata = "ajaxreq=true"; " var formAction = window.document.forms[0].action; " + "req.open("POST",formAction,true); " + "req.setRequestHeader("Content-Type","application/x-www-form-urlencoded"); " +    More>>

I have a javascript function for a POST request from XMLHttprequest object.The post-back is handled within the decode function of the component which generates the AJAX request.
The javascript request looks as follows:
function lookup(field) {
....
if (window.XMLHttpRequest) { req = new XMLHttpRequest(); }
else if (window.ActiveXObject) { req = new ActiveXObject("Microsoft.XMLHTTP"); }
var formdata = "ajaxreq=true";
" var formAction = window.document.forms[0].action;
" +
"req.open("POST",formAction,true);
" +
"req.setRequestHeader("Content-Type","application/x-www-form-urlencoded");
" +
req.onreadystatechange = processXMLResponse;
req.send(formdata);
}

This request is generated from within the directoryBrowser.jsp itself.
This request is not being recognized as a post-back by the JSF framework ,successful as it is not causing the decode method of the component to be executed.

What is wrong?
When i print out the responseText of the request object from the callback function, i get teh html of the page printed out.The responsexml is null.

   <<Less

Re: AJAX post-back

Posted By:   Anonymous  
Posted On:   Sunday, March 4, 2007 10:31 AM

You say that you are able to view data needed using responseText property and not with responseXML right?? in the JSP where your are processing the request and sending the response, are you setting the response type as xml??? check that..




Code snippet for you


<%@ page import="com.mot.iden.pt.dto.ASPMonthlyPriceScreenDTO" %>
standalone="yes"?>
<%
response.setContentType("text/xml");
ASPMonthlyPriceScreenDTO dto = (ASPMonthlyPriceScreenDTO) request.getAttribute("TABLE_PRICES");
if( dto == null )
{
dto = new ASPMonthlyPriceScreenDTO();
}
%>

<%=dto.getBpp()%>
<%=dto.getAdders()%>
<%=dto.getAddersSelected()%>
<%=dto.getUpgrades()%>
<%=dto.getUpgradesSelected()%>
<%=dto.getCo_op()%>
<%=dto.getMisc()%>
<%=dto.getMiscNotes()%>
<%=dto.getNetR()%>
<%=dto.getNetRIds()%>
<%=dto.getPercentDisc()%>
<%=dto.getAbsoluteAmt()%>
<%=dto.getIdSet()%>



now I get the response back as XML. in the callback function, just say


as req is your request object..

var response = req.responseXML.documentElement;



from now on you can access data in it using


var bpp = response.getElementsByTagName('bpp')[0].firstChild.text



Is this what u expected??
About | Sitemap | Contact