Hi all! When I run the following it gives a scary warning in IE saying there is something going on that I am not in control of. And in Firefox the javascript tester returns ‘permission denied to call method XMLHttpRequest.open’. What am I doing wrong?
[code=html]
<html>
<head>
<script type=”text/javascript”>
/*<![CDATA[*/
function loadXMLDoc(url)
{
// branch for native XMLHttpRequest object
if (window.XMLHttpRequest) {
req = new XMLHttpRequest();
req.onreadystatechange = processReqChange;
req.open(“GET”, url, true);
req.send(null);
// branch for IE/Windows ActiveX version
} else if (window.ActiveXObject) {
req = new ActiveXObject(“Microsoft.XMLHTTP”);
if (req) {
req.onreadystatechange = processReqChange;
req.open(“GET”, url, true);
req.send();
}
}
}
function processReqChange()
{
// only if req shows “complete”
if (req.readyState == 4) {
// only if “OK”
if (req.status == 200) {
// …processing statements go here…
response = req.responseXML.documentElement;
method =
response.getElementsByTagName(‘method’)[0].firstChild.data;
result =
response.getElementsByTagName(‘result’)[0].firstChild.data;
eval(method + ‘(”, result)’);
}
}
}
function checkName(input, response)
{
if (response != ”){
// Response mode
message = document.getElementById(‘nameCheckFailed’);
if (response == ‘1’){
message.className = ‘error’;
}else{
message.className = ‘hidden’;
}
}else{
// Input mode
url =
‘http://myhomewebserver.co.uk/xml.xml?q=’ + input;
loadXMLDoc(url);
}
}
/*]]>*/
</script>
<style type=”text/css”>
/*<![CDATA[*/
span.hidden{
display: none;
}
span.error{
display: inline;
color: black;
background-color: pink;
}
/*]]>*/
</style>
</head>
<body>
<input id=”username” name=”username” type=”text”
onblur=”checkName(this.value,”)” />
<span class=”hidden” id=”nameCheckFailed”>
This name is in use, please try another.
</span>
</body>
</html>
Here’s the XML page output:
[code=html]
<?xml version=”1.0″ encoding=”UTF-8″ standalone=”yes”?>
<response>
<method>checkName</method>
<result>1</result>
</response>