praveen rapelli

praveen rapelli

  • NA
  • 28
  • 39.7k

Call webservice in html javascript which works all browsers(on internet )

Jun 21 2011 6:33 AM
<html>
   <head>
       <title>Consume Count Service</title>
       <script type="text/javascript" language="javascript" >
function outputResult(str){
var xmlhttp = null;
alert(xmlhttp);
if (window.XMLHttpRequest) {
  xmlhttp = new XMLHttpRequest();
  if ( typeof xmlhttp.overrideMimeType != 'undefined') {
    xmlhttp.overrideMimeType('text/xml');
  }
} else if (window.ActiveXObject) {
  xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {
  alert('Perhaps your browser does not support xmlhttprequests?');
}
str='modi';
flag='s';
var url= "http://example.com/webservice.asmx/webmethodname?prefixText="+str+"&flag="+flag;

xmlhttp.open('GET', url, true);
xmlhttp.send(null);
xmlhttp.onreadystatechange = function() {
  if (xmlhttp.readyState == 4 && xmlhttp.status == 200) {
 
    // do something with the results
  } else {
    // wait for the call to complete
   
  }
};

 var myString=xmlHttp.responseText;
                                                              
                                                            
}
</script>
</head>
<body onload="outputResult(this.value)">  
</body>
</html>

Question:This is not working in firefox,opera,internet explorer..etc in online(internet).It works perfectly in local system.How to solve this problem,please tell me........

Answers (4)