This is Interesting: Free Magazines for Graphics designers and webmasters  


Home > Archive > Microsoft XML > April 2007 > XML httprequest





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author XML httprequest
warren@rsvpcare.com

2007-04-12, 6:17 pm

I am very new to xml. Please bare with me.The application I am having
trouble with is as follows:

Integrating an XML http request into my current asp page.

I have a data entry form done is asp. One of the fields in that form
is a phonenumber field. Using this field I will query the whitepages
xml api on a seperate domain and retrieve address information which I
can then store in my asp.

I have found the code below which has an actual example of an XML http
request in it; however, when I query the server, I receive an access
denied js error.

Am I missing something?

<html>
<head>
<script type="text/javascript">
var xmlhttp

function loadXMLDoc(url)
{
xmlhttp=null
// code for Mozilla, etc.
if (window.XMLHttpRequest)
{
xmlhttp=new XMLHttpRequest()
}
// code for IE
else if (window.ActiveXObject)
{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP")
}
if (xmlhttp!=null)
{
xmlhttp.onreadystatechange=state_Change
xmlhttp.open("GET",url,false)
xmlhttp.send(null)
}
else
{
alert("Your browser does not support XMLHTTP.")
}
}


function state_Change()
{
// if xmlhttp shows "loaded"
if (xmlhttp.readyState==4)
{
// if "OK"
if (xmlhttp.status==200)
{
alert("XML data OK")
document.getElementById('A1').innerHTML=xmlhttp.status
document.getElementById('A2').innerHTML=xmlhttp.statusText
document.getElementById('A3').innerHTML=xmlhttp.responseText
}
else
{
alert("Problem retrieving XML data:" + xmlhttp.statusText)
}
}
}

</script>
</head>

<body onload="loadXMLDoc('http://enterprise.w3data.com/directaccess?
ver=2.0&type=p&data=n&p=4253921111')">
<h2>Using the HttpRequest Object</h2>

<p><b>status:</b>
<span id="A1"></span>
</p>

<p><b>status text:</b>
<span id="A2"></span>
</p>

<p><b>response:</b>
<br><span id="A3"></span>
</p>

</body>
</html>

Martin Honnen

2007-04-12, 6:17 pm

warren@rsvpcare.com wrote:

> I have found the code below which has an actual example of an XML http
> request in it; however, when I query the server, I receive an access
> denied js error.


With XMLHttpRequest inside the browser you can only connect back to the
server the HTML document with the script comes from. That is the same
origin policy, applied for security reasons. So you have to make a
request to your own server and then, within your ASP page, you can make
a request to that other server, receive the data and send it to the client.

--

Martin Honnen --- MVP XML
http://JavaScript.FAQTs.com/
Sponsored Links


Copyright 2003 - 2008 forum4designers.com  Software forum  Computer Hardware reviews