gary
gary

Reputation: 1

Web Service call using javascript returns nothing in responseXML

I see this same question asked a few times in this forum and I have applied the suggested answers but I continue to have a problem. That problem being that when I call a web service using javascript the response comes back empty, while I successfully receive data (a valid XML document) calling the web service in any browser.

Here is my javascript code in an HTML page:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/xml">
<title> MY HTML page        </title>


<script language="JavaScript">
function doWebSvce()
{

    if (window.XMLHttpRequest) { 
    xhttp=new XMLHttpRequest();

    }
    else if (window.ActiveXObject) { 
         XObject("Microsoft.XMLHTTP"); 
         xhttp=new ActiveXObject("Microsoft.XMLHTTP");

}

var url = "http://www.webservicex.net/stockquote.asmx/GetQuote?symbol=IBM"; 
xhttp.open("GET", url, true); 
xhttp.onreadystatechange = getData; 
xhttp.send("");     

}//end doWebSvce

function getData() 
{ 
if (xhttp.readyState == 4)  
{ 

alert("2nd in getData... \r\xhttp.readyState = "+ xhttp.readyState +"  \r\n  
      xhttp.status= "+ xhttp.status +
 " \r\n  responseXML = "+ xhttp.responseXML + " \r\n   responseText= "+  
      xhttp.responseText);

    var myXml=xhttp.responseXML;

     //.... do stuff with myXML variable....
 }

The alert statements shows: "2nd in getData... xhttp.readystate = 4 xhttp.status = 0 xhttp.responseXML = null responseText = blank"

As I stated, I can hit on the web service indicated in the url and receive an XML document without a problem.

I have executed this same code in both FireFox and IE on two different machines giving me the same problem, so I'm thinking the problem is either in my code or the way the web site is responding to my request.

Any suggestions is certainly appreciated. Thanks to all for your time.

Upvotes: 0

Views: 606

Answers (1)

rciq
rciq

Reputation: 1309

It looks like you are attempting to make a cross-site request and that's the problem. Cross-site requests are not possible with XmlHttp.

Upvotes: 2

Related Questions