views:

48

answers:

1

The script below work perfectly in IE for the XML respond. But seems i cant figured out how to run on Firefox or Chorme. Try few modification but still not able to run it. Kindly need assistant.

<script type="text/javascript" language="javascript"> 
var xmlhttp; 
var timeStamp;

var currentTime = new Date()
var month = currentTime.getMonth() + 1
var day = currentTime.getDate() //remove the + 1  afterwards
var year = currentTime.getFullYear()
var hour = currentTime.getHours()
var minutes = currentTime.getMinutes()
var second = currentTime.getSeconds() + 1


timeStamp =  day + "/" + month + "/" + year + " " + hour + ":" + minutes + ":" + second;



function on_click() 

{ 



var xmlToSend = "<?xml version='1.0' encoding='utf-8'?>"; 
xmlToSend += "<soap:Envelope xmlns:xsi='http://www.w3.org/2001/XMLSchema-instance' "; 
xmlToSend += "xmlns:xsd='http://www.w3.org/2001/XMLSchema' "; 
xmlToSend += "xmlns:soap='http://schemas.xmlsoap.org/soap/envelope/'&gt;"; 
xmlToSend += "<soap:Body><Welcomescreen Sender='SENDERDDRESS' TimeStamp='28/10/2009 16:49:31' Type='1' Workshop='SG' RequireAppointmentDate='2010/01/04' xmlns='http://www.SENDERDDRESS.com/integration'/&gt;"; 
xmlToSend += "</soap:Body></soap:Envelope>"; 

/


var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 
xmldoc.loadXML(xmlToSend); 


if (window.XMLHttpRequest)
  {// code for IE7+, Firefox, Chrome, Opera, Safari
  xmlhttp=new XMLHttpRequest();
  }
else
  {// code for IE6, IE5
  xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
  }


xmlhttp.onreadystatechange = state_Change; 

xmlhttp.open("POST", "http://SENDERDDRESS:4509/resd", false); 
xmlhttp.setRequestHeader ("SOAPAction", "http://www.mhe.com/SRP/requestVinRequest");  
xmlhttp.setRequestHeader ("Content-Type", "text/xml"); 
xmlhttp.setRequestHeader ("User-Agent", "Jakarta Commons-HttpClient/3.0.1"); 
xmlhttp.setRequestHeader ("Host", "SENDERDDRESS:4509"); 
xmlhttp.setRequestHeader ("Content-Length", "391"); 
xmlhttp.send(xmldoc); 



var objResponse = document.getElementsByTagName("Appointment"); 

objResponse.innerText = xmlhttp.responseXML.xml; 

} 
function state_Change() 

{ 
if (xmlhttp.readyState==4) 
{ 
if (xmlhttp.status==200) 
{ 
txt="<table align='right' border='1' width='400'><tr><th><font color='#d9d7d7' size='4' face='verdana'>Time</font></th><th><font color='#d9d7d7' size='4' face='verdana'>Plate No.</font></th><th><font color='#d9d7d7' size='4' face='verdana'>Status</font></th></tr>";
    x=xmlhttp.responseXML.documentElement.getElementsByTagName("Appointment");
    for (i=0;i<x.length;i++)
      {

      xx=x[i].getElementsByTagName("AppointmentTime");
        {
        try
          {
          txt=txt + "<td><font size = 5>" + xx[0].firstChild.nodeValue + "</font></td>";
          }
        catch (er)
          {
          txt=txt + "<td> </td>";
          }
        }

      xx=x[i].getElementsByTagName("NumberPlate");
        {
        try
          {
          txt=txt + "<td><font size = 5>" + xx[0].firstChild.nodeValue + "</font></td>";
          }
        catch (er)
          {
          txt=txt + "<td> </td>";
          }
        }

   xx=x[i].getElementsByTagName("statusCode");
        {
        try
          {
          txt=txt + "<td><font size = 5>" + xx[0].firstChild.nodeValue + "</font></td>";
          }
        catch (er)
          {
          txt=txt + "<td> </td>";
          }
        }  
      txt=txt + "</tr>";
      }
    txt=txt + "</table>";
 document.getElementById('txtCDInfo').innerHTML=txt;
} 

else 

{ 


} 

} 

} 
</script> 
+1  A: 

I see two issues. One is that you have a stray / just after the series of xmlToSend += lines, which is a syntax error, and then there's this:

var xmldoc = new ActiveXObject("Microsoft.XMLDOM"); 

ActiveXObject is not standard, it's an IE-specific thing. Unlike the other place you're using it, that line is not conditional.

You can just pass the xmlToSend string directly into XMLHttpRequest#send (link), you don't need to make an XML document out of it first. It'll just have to get turned back into a string again to be sent.

If you really want to actually create an XML document object, you can use DOMImplementation#createDocument (e.g., document.implementation.createDocument) on compliant browsers.

Off-topic: JavaScript libraries can make your life a bit easier in the Ajax area (and many others). Something like jQuery, Closure, Prototype, YUI, or any of several others may save you some time.

T.J. Crowder
T.J, I already move out the specific IE ActiveXObject and only using XMLHttpRequest to pass and in work in IE but still not in FF. However I did a TCP trace on both of the browser output and found out the XML header scheme in FF output differently and server respond was error.
Arif
Output send IE: POST /domain HTTP/1.1 Accept: */* Accept-Language: en-us Referer: http://localhost/appointment/welcome.html soapaction: http://www.domain.com/SRP/requestVinRequest Content-Type: text/xml User-Agent: Jakarta Commons-HttpClient/3.0.1 Accept-Encoding: gzip, deflate Host: localhost:8080 Content-Length: 415 Connection: Keep-Alive Cache-Control: no-cache
Arif
Output send FF:OPTIONS /domain HTTP/1.1Host: localhost:8080User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.10) Gecko/20100914 AskTbARS/3.8.0.12304 Firefox/3.6.10 (.NET CLR 3.5.30729)Accept: text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8Accept-Language: en-us,en;q=0.5Accept-Encoding: gzip,deflateAccept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7Keep-Alive: 115Connection: keep-aliveOrigin: http://localhostAccess-Control-Request-Method: POSTAccess-Control-Request-Headers: soapaction,user-agent
Arif
@Arif: *"I already move out the specific IE ActiveXObject and only using XMLHttpRequest"* I'm talking about where you're creating the `Microsoft.XMLDOM` object, not the `XMLHttpRequest` object. Again, the code calling `ActiveXObject` to create the `XMLDOM` is **not** conditional (look just above where you branch when creating the `XMLHttpRequest`).
T.J. Crowder