Javascript to Post XML data to uri and get xml response

Javascript to Post XML data to uri and get xml response

Here is the html code to post xml data. Copy in notepad and save as html.

 <title>WMS Test</title>  
 <script language="JavaScript">  
  function doit()  
   var url = '';  
   var method = 'POST';  
   var postData =  
    '<TRANS_MCU><!-- The root Is the transaction name. --><TRANS_COMMON_PARAMS> <MCU_TOKEN>0</MCU_TOKEN><MCU_USER_TOKEN>0</MCU_USER_TOKEN><MESSAGE_ID>1</MESSAGE_ID></TRANS_COMMON_PARAMS><!-- The next element Is the action (Login), And below it are the actions parameters, in this case, the Login parameters. --> <ACTION> <LOGIN><!-- The next parameters are the MCU IP And the port number. --><MCU_IP><IP></IP><LISTEN_PORT>80</LISTEN_PORT><HOST_NAME/></MCU_IP><!-- The user And password strings.--><USER_NAME>PMC</USER_NAME><PASSWORD>PMC</PASSWORD><STATION_NAME>EMA.F3-JUDITHS</STATION_NAME><COMPRESSION>false</COMPRESSION></LOGIN></ACTION></TRANS_MCU>';  
   var req = new XMLHttpRequest();"POST", url, true);  
   // req.setRequestHeader('User-Agent', 'XMLHTTP/1.0');  
   req.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');  
   req.onreadystatechange = function () {  
    if (req.readyState != 4) return;  
    if (req.status != 200 && req.status != 304) {  
     alert('HTTP error ' + req.status);  
   if (req.readyState == 4) return;  
 <input type="button" value="doit" onclick="doit()"/>  
 If you get error “No 'Access-Control-Allow-Origin' header is present on the requested resource” . you are doing an XMLHttpRequest to a different domain than your page is on. So the browser is blocking it as it usually allows a request in the same origin for security reasons. You need to do something different when you want to do a cross-domain request.  
 The easy way is to just add the extension in google chrome to allow access using CORS.  
 Just enable this extension whenever you want allow access to no 'access-control-allow-origin' header request.  
 In Windows, paste this command in run window  
 <b>chrome.exe --user-data-dir="C:/Chrome dev session" --disable-web-security </b><br/><br/>  
 this will open a new chrome browser which allow access to no 'access-control-allow-origin' header request.  


Most Viewed Post

solution for facebook waiting

Connect Sony XPLOD MEX-BT2500 Bluetooth CD Receiver with ur mobile

Crystal Report : Show data horizontally (Left to right) i.e. columns as rows

Google+ Followers