Ajax GET for URL fails

M

mflll

I am having trouble getting my simple AJAX program to work at my
current
University. Here is one of the programs that is giving problems. I
tried
it in and Mozilla/5.0 Gecko/20050923 under Fedora Linux

I see the alert's "V" and "V Two" The latter says
"null[XMLHttpRequest} aitivie sob ject undefined"
so I know that it retrieving the XMLHttpRequest object from the system.

It hangs after that; that is, I don't see "here get" alert.
Needless, to say, I confirmed with browser that the URL was available.

Thanks for any help you can provide. My students and myself were
excited
about doing AJAX in my Graphical User Interface class. I got it to
work
at another University when I was staying in another city, see below.
Thus, I was surprised and disappointed that it won't work here.

Dr. Laurence Leff, Pager 309 367 0787
Associate Professor of Computer Science, 1 University Circle
Western Illinois University Macomb IL 61455

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" >
var HO;
document.write("Testingasdf");
function getRequestObject (){

xmlhttp = new XMLHttpRequest();
alert ("null" + window.XMLHttpRequest + " acitvie sob ject " +
window.ActiveXObject);
return xmlhttp ;
}

function Q () {
var code = HO.readyState;
alert (HO.readyState);
if (code == 4) {
alert ("code four")

var MyDocument = HO.responseXML;
var XXNode = MyDocument.getElementsByTagName('xx');
var YYNode = MyDocument.getElementsByTagName('yy');

xx = XXNode[0].firstChild.data;
yy = YYNode[0].firstChild.data;
document.QQ.xxReceive.value = xx;
document.QQ.yyReceive.value = yy;
}




}
function V () {
alert("v");
HO = getRequestObject();
alert ("V Two" + HO);
Ho_Open("GET","http://www.wiu.edu/users/mflll/U.xml");
alert ("here get" + HO+"|" );
Ho_Onreadystatechange=Q;
alert (" ho onready statechange")
HO.send(null);

}
</script>
</HEAD>
<BODY>
<P>
Text before Form
<P>
<form name="QQ" >
<input TYPE = "BUTTON" NAME="qq" VALUE="PressMe"
onClick="V()" />
<input TYPE="text" name="xxReceive"/>
<INPUT TYPE="text" name="yyReceive"/>
</form>
</BODY>

The program below worked under an older version of internet explorer
at another University near where I was staying with my mother that let
me use
their computer as a courtesy.

It does not work now under a more current version of Internet Explorer.

<html>
<head>
<SCRIPT LANGUAGE="JavaScript" >
var HO;
document.write("Testingd");
function getRequestObject (){
try {
xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
}
catch (e) {
try {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
catch (E) {
alert ("second catch");
}
}
return xmlhttp ;
}

function Q () {
var code = HO.readyState;
alert (HO.readyState);
if (code == 4) {
alert ("code four")

var MyDocument = HO.responseXML;
var XXNode = MyDocument.getElementsByTagName('xx');
var YYNode = MyDocument.getElementsByTagName('yy');

xx = XXNode[0].firstChild.data;
yy = YYNode[0].firstChild.data;
document.QQ.xxReceive.value = xx;
document.QQ.yyReceive.value = yy;
}




}
function V () {
alert("v");
HO = getRequestObject();
Ho_Open("GET","http://www.wiu.edu/users/mflll/U.xml");
alert ("here get")
Ho_Onreadystatechange=Q;
alert (" ho onready statechange")
HO.send(null);

}
</script>
</HEAD>
<BODY>
<P>
Text before Form
<P>
<form name="QQ" >
<input TYPE = "BUTTON" NAME="qq" VALUE="PressMe"
onClick="V()" />
<input TYPE="text" name="xxReceive"/>
<INPUT TYPE="text" name="yyReceive"/>
</form>
</BODY>
 
W

web.dev

<SCRIPT LANGUAGE="JavaScript" >

The language attribute is deprecated, use the type attribute instead:

function getRequestObject (){

xmlhttp = new XMLHttpRequest();
alert ("null" + window.XMLHttpRequest + " acitvie sob ject " +
window.ActiveXObject);
return xmlhttp ;
}

In this current implementation of your function, you're only supporting
non-IE browsers (at least until IE7 comes out). You can do something
like the following:

if(window.XMLHttpRequest)
{
//for IE7, Mozilla, Safari, etc: use native object
var xmlHttp = new XMLHttpRequest();
}
else if(window.ActiveXObject)
{
//use ActiveX control for IE5.x and IE6
var xmlHttp = new ActiveXObject("Microsoft.XMLHTTP");
}
document.QQ.xxReceive.value = xx;
document.QQ.yyReceive.value = yy;

A more standard way of accessing the form and its elements is through
the square bracket notation:

document.forms["QQ"].elements["xxReceive"].value = xx;
document.forms["QQ"].elements["yyReceive"].value = yy;

The open method also has a third parameter that takes a boolean
indicating whether you would like this to be an asynchronous request or
not. Usually true is passed.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,780
Messages
2,569,611
Members
45,277
Latest member
VytoKetoReview

Latest Threads

Top