/    Sign up×
Community /Pin to ProfileBookmark

XmlHttpRequest! phpnovice?… Anyone?…

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>

[/code]

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>
[/code]

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51Jul 09.2005 — The access denied happens if you are pulling data from another domain or running it off the desktop.

Look at the second example on this page: http://radio.javaranch.com/pascarello/2005/06/24/1119626686861.html

You should see the enable security statements. That helps with firefox.

Eric
Copy linkTweet thisAlerts:
@bokehauthorJul 09.2005 — Thanks! I was running it from localhost.
×

Success!

Help @bokeh spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.25,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...