Click here to Skip to main content
15,915,093 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi ,
I am trying to invoke web service via java script It works great with IE 9 but not works on other browsers Please help me to fix the issue

XML
<script type="text/javascript" language="javascript">
        var xmlHttp;
        function SoapCall() {

            // creatng the xmlHttp object
            if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
                xmlHttp = new XMLHttpRequest();
            }
            else {// code for IE6, IE5
                xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
            }
            // Calling the web service using post and true means asynchronous call
            xmlHttp.open("post", "http://www.webservicex.net/CurrencyConvertor.asmx", true);
            // Setting the request header to let the web service identify the soap request we would be sending

            xmlHttp.setRequestHeader("Content-Type", "text/xml; charset=utf-8");
            xmlHttp.setRequestHeader("Origin", "http://www.webserviceX.NET");
            xmlHttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");

           // xmlHttp.setRequestHeader("Access-Control-Allow-Origin", "http://172.27.47.144");
            xmlHttp.setRequestHeader("SOAPAction", "http://www.webserviceX.NET/ConversionRate");

            var soapRequest = '<?xml version="1.0" encoding="utf-16"?>' +
'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema">' +
  '<soap:Body>' +
    '<ConversionRate xmlns="http://www.webserviceX.NET/">' +
      '<FromCurrency>USD</FromCurrency>' +
      '<ToCurrency>INR</ToCurrency>' +
    '</ConversionRate>' +
  '</soap:Body>' +
'</soap:Envelope>';


            xmlHttp.onreadystatechange = function () {
                if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
                    alert(xmlHttp.responseText);
                }
            }
            xmlHttp.send(soapRequest);


        }
    </script>
Posted
Comments
Sandeep Mewara 11-May-12 2:13am    
Do you get any error? What is the workflow result? Did you debug?

Code looks fine.

1 solution

If this doesn't work in the other browsers , then your SVC seems to already be supporting this, but to be sure, use Fiddler2 to see what is going on.

The Access-Control-Allow-Origin header is used on the resource being requested, not on the page requesting it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900