By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,441 Members | 998 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,441 IT Pros & Developers. It's quick & easy.

Ajax GET for URL fails

P: n/a
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>

Feb 3 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

mf***@wiu.edu wrote:
<SCRIPT LANGUAGE="JavaScript" >
The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">
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;
HO.open("GET","http://www.wiu.edu/users/mflll/U.xml");


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.

Feb 3 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.