Thursday, June 16, 2016

Call SOAP Webservice from javascript

Example


<html>
   <head>
      <title>SOAP Sample</title>
      <script type="text/javascript">
         function soapCall() {
             var xmlhttp = new XMLHttpRequest();
             xmlhttp.open('POST', 'soapurl', true);
             // build SOAP request
             var sr =
                 '<?xml version="1.0" encoding="utf-8"?>' +
                 '<soapenv:Envelope ' +
                     'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" ' +
                     'xmlns:api="url" ' +
                     'xmlns:xsd="http://www.w3.org/2001/XMLSchema" ' +
                     'xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/">' +
                     '<soapenv:Body>' +
                         '<api:parm1>' +
                             '<api:param>2014_DAY_339_2</api:param>' +
                         '</api:parm1>' +
                     '</soapenv:Body>' +
                 '</soapenv:Envelope>';
        
             xmlhttp.onreadystatechange = function () {
                 if (xmlhttp.readyState == 4) {
                     if (xmlhttp.status == 200) {
         alert('--'+xmlhttp.response);
                     }
                 }
             }
             // Send the POST request
             xmlhttp.setRequestHeader('Content-Type', 'text/xml');
             xmlhttp.send(sr);
         }
        
      </script>
   </head>
   <body>
      <script type="text/javascript">
         soapCall();
      </script>
   </body>
   <html>
</html>

No comments: