I will try to be as precise as possible in explaining the situation I am facing. I am developing a Struts 2 based web application and in one of the page, I use Jquery 1.4.4 to make Ajax calls(POST) to Struts2 Action classes and get back an XML which I iterate through and build a select box and render it on UI.
This piece of code works fine on my Local WAS 6.1 development environment. But not quite on the production server(same WAS version). The select box is built properly in Local env but not in production.
The Ajax Code is below :
$.ajax({ url: 'DisplaySplitCriteriaValuesAction',
type:'POST',
dataType: "xml",
data:{ splitCriteriaType: $.trim($(this).text()) },
success: function( xmlResponse ) {
buildSelectBoxNoDropDown(xmlResponse, "serviceActivitiesValue", "#ServiceActivitiesValueSelectionDIV");
$('#serviceActivitiesValue').bind({
change: function(){
if($(this).val() != '-1'){
makeDefault(this,'defValueForSA');
}
}
});
} });
function buildSelectBoxNoDropDown(xmlData, selectBoxName, whereToDisplayedDiv){
var selectBoxhtml = '<select name="'+selectBoxName+'" id="'+selectBoxName+'"size="12" class="select_optionsBOX">';
$(xmlData).find('name').each(function(){
selectBoxhtml = selectBoxhtml+'<option value="'+$(this).text()+'">'+$(this).text()+'</option>';
});
selectBoxhtml = selectBoxhtml+'</select>';
$(whereToDisplayedDiv).empty();
$(whereToDisplayedDiv).append(selectBoxhtml);
}
Sample XML structure I am returning from Action class
<SplitCriteriaValues><name>Sample SC Value 1</name><name>Sample SC Value 2</name><name>Sample SC Value 3</name></SplitCriteriaValues>
The surprising part is I see the XML response when debugging using Firebug. When I compare the responses in both dev and prod environments, both match however, there is an extra tab called “XML” right beside “response” tab. I am not sure if that makes any difference.
Is there anything that has to be accounted for when moving from one environment to another? Any pointers to resolve this kind of weird behavior will be helpful.
Thanks
I was finally able to figure this out. Though Firebug was showing a response, the missing XML tab meant the production server never knew the content type it was receiving (or assumed it was simple text rather than XML), A quick look at the response header also confirmed that the response content type by default was text/plain.
So All I had to do was set the content type to “text/xml” in the Action class and that fixed my problem. some how my local server did not consider the content type an issue but the production one did.
Thanks.
Sandeep