I am using XML in web scripts to dynamically refresh portions of web pages. For e.g. If dynamically populating one select box depending on the value chosen from another select box. I am attaching a sample
JS code I am using. The idea is to submit an xml to an ASP page. The ASP page processes it and returns an XML back. This reply XML is parsed with the help of Javascript to refresh portions of web page.
function func_retrieve_fabric_types()
{
var str_browser=func_get_browser();
var str_xml="";
//alert(document.frm_test.cbo_fabric_categories.opti ons[document.frm_test.cbo_fabric_categories.selectedIn dex].value);
if(!((document.frm_test.cbo_fabric_categories.opti ons[document.frm_test.cbo_fabric_categories.selectedIn dex].value)==""))
{
str_xml+="<xml_to_be_submitted><request_xml><fabri c_cat_id>"+document.frm_test.cbo_fabric_categories .options[document.frm_test.cbo_fabric_categories.selectedIn dex].value+"</fabric_cat_id></request_xml></xml_to_be_submitted>";
if(str_browser=="IE")
{
var obj_http=new ActiveXObject("Microsoft.XMLHTTP");
}
else if(str_browser=="NS6")
{
alert("browser is NS 6 or later");
var obj_http=new XMLRemoteRequest();
}
var str_url="testfb.asp";
var str_http_method="post";
obj_http.open(str_http_method,str_url,false);
obj_http.SetRequestHeader("Content-Type","application/x-www-form-urlencoded");
obj_http.send(str_xml);
var str_reply=obj_http.ResponseText;
//processes return xml
alert (str_reply);
var xmlResponse = str_reply;
var objXmlDOM=new ActiveXObject("Microsoft.XMLDOM");
if(!objXmlDOM.loadXML(xmlResponse))
{
alert("Could not load xml object");
}
else
{
var i_option_id = objXmlDOM.selectNodes("/options/option_id");
var str_option_text = objXmlDOM.selectNodes("/options/option_text");
var i_loop;
var i_num_options=1;
document.frm_test.cbo_fabric_types.options.length= 1;
for(i_loop=0;i_loop<i_option_id.length;++i_loop)
{
document.frm_test.cbo_fabric_types.options.length+ =1;
i_num_options++;
document.frm_test.cbo_fabric_types.options[i_num_options-1].value=i_option_id[i_loop].text;
document.frm_test.cbo_fabric_types.options[i_num_options-1].text=str_option_text[i_loop].text;
}
}
}
}
I am not getting the response XML back from server when the browser is netscape is 6 or 7.
This code will work only in IE (so that I have to tell the clients to use IE alone to run the intra office applications). I would like to know whether there are any similar code / technique that will make it run on netscape / mozilla ?
Thanks for reading.