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

Trying To Invoke a WebService

P: n/a
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

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) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>
Aug 13 '05 #1
Share this Question
Share on Google+
4 Replies


P: n/a
"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:be********************@comcast.com...
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true? I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

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) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>


I don't know about ASP.NET but this works for me:

<html>
<head>
<title>xml_zip.htm</title>
<script type="text/javascript">
var req;
var response;
var city;
var state;

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) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state =
response.getElementsByTagName('state')[0].firstChild.data;
alert(city + ", " + state);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" + req.statusText);
}
}
}

function loadxml() {
loadXMLDoc('http://www.wengert.org/zipcodes.asmx/GetZip?z=' +
document.forms[0].txtZIP.value);
}
</script>
</head>
<body>
<form>
<input type="text" name="txtZIP" size="5" maxlength="5" value="">
<input type="button" value="Lookup" onclick="loadxml()">
<br>City, State :
<input type="text" name="txtcity">
<input type="text" name="txtstate">
<br>
<textarea name="output" cols="100" rows="30"></textarea>
</form>
</body>
</html>
I changed your
function loadxml(form) {
to
function loadxml() {
as well as the indentation for (my) readability.
Aug 13 '05 #2

P: n/a
Thanks for the response. I too can get it to work if I use an old style
(ASP) form but it appears that the 2 objects I mentioned are not valid in an
ASP.NET environment?

Wayne

"McKirahan" <Ne**@McKirahan.com> wrote in message
news:F5********************@comcast.com...
"Wayne Wengert" <wa***********@wengert.org> wrote in message
news:be********************@comcast.com...
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is

true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET. How can I accomplish this?

Wayne

================= code ==============
<script language="Javascript">
<!--

var req;
var response;
var city;
var state;

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) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city = response.getElementsByTagName('city')[0].firstChild.data;
state = response.getElementsByTagName('state')[0].firstChild.data;
alert(city);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" +
req.statusText);
}
}
}

function loadxml(form) {
loadXMLDoc('http://www.wengert.org/' +
'zipcodes.asmx/GetZip?z=' + document.forms[0].txtZIP.value);
}

//-->

</script>


I don't know about ASP.NET but this works for me:

<html>
<head>
<title>xml_zip.htm</title>
<script type="text/javascript">
var req;
var response;
var city;
var state;

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) {
isIE = true;
req = new ActiveXObject("Microsoft.XMLHTTP");
if (req) {
req.onreadystatechange = processReqChange;
req.open("GET", url, true);
req.send();
}
}
}

function processReqChange() {
if (req.readyState == 4) {
if (req.status == 200) {
document.forms[0].output.value = req.responseText
response = req.responseXML.documentElement;
city =
response.getElementsByTagName('city')[0].firstChild.data;
state =
response.getElementsByTagName('state')[0].firstChild.data;
alert(city + ", " + state);
document.forms[0].txtcity.value = city
document.forms[0].txtstate.value = state
} else {
alert("Please enter a valid zip code:\n" + req.statusText);
}
}
}

function loadxml() {
loadXMLDoc('http://www.wengert.org/zipcodes.asmx/GetZip?z=' +
document.forms[0].txtZIP.value);
}
</script>
</head>
<body>
<form>
<input type="text" name="txtZIP" size="5" maxlength="5" value="">
<input type="button" value="Lookup" onclick="loadxml()">
<br>City, State :
<input type="text" name="txtcity">
<input type="text" name="txtstate">
<br>
<textarea name="output" cols="100" rows="30"></textarea>
</form>
</body>
</html>
I changed your
function loadxml(form) {
to
function loadxml() {
as well as the indentation for (my) readability.

Aug 13 '05 #3

P: n/a


Wayne Wengert wrote:
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is true?
I tried viewing those objects status but they do not appear to be valid
objects in ASP.NET.
What you have below is client-side JavaScript code which is executed in
the browser and has no relevance to ASP.NET which is executed on the
server. Of course XMLHttpRequest respectively Microsoft.XMLHTTP are
used to load data from a HTTP server but whether that server runs
classic ASP or ASP.NET or JSP or PHP or no server side scripting
framework at all is not relevant to using XMLHttpRequest or
Microsoft.XMLHTTP on the client. So the statement "they do not appear to
be valid objects in ASP.NET" does not really make sense, the client has
to support the objects and XMLHttpRequest is supported by Mozilla,
Netscape 7/8, Opera 8, Safari 1.2, Konqueror 3.3, and Microsoft.XMLHTTP
by IE 5 and later on Windows.
<script language="Javascript"> if (window.XMLHttpRequest) { } else if (window.ActiveXObject) {
If something does not work as you want then it can have many reasons, if
you use Mozilla or Firefox check the JavaScript console first.
loadXMLDoc('http://www.wengert.org/'


You need to be aware that with normal security settings XMLHttpRequest
can load data only from the same HTTP server as the HTML document with
the script has been loaded from. So perhaps you are trying to access
that web service on www.wengert.org with a script in a HTML document
loaded from another server and then simply get no access.

--

Martin Honnen
http://JavaScript.FAQTs.com/
Aug 13 '05 #4

P: n/a
Marttin;

Thanks for the response. I think I need to do some studying to get an
understanding of all the items you mentioned.

Wayne

"Martin Honnen" <ma*******@yahoo.de> wrote in message
news:42***********************@newsread4.arcor-online.net...


Wayne Wengert wrote:
I found a code sample that allows you to use a 5 digit zip code to lookup
the correct city and state using a Web Service (ASP.NET). When I run the
javascript code (see below) on my aspx page neither the "if
(window.XMLHttpRequest)" nor the " else if (window.ActiveXObject) " is
true? I tried viewing those objects status but they do not appear to be
valid objects in ASP.NET.


What you have below is client-side JavaScript code which is executed in
the browser and has no relevance to ASP.NET which is executed on the
server. Of course XMLHttpRequest respectively Microsoft.XMLHTTP are used
to load data from a HTTP server but whether that server runs classic ASP
or ASP.NET or JSP or PHP or no server side scripting framework at all is
not relevant to using XMLHttpRequest or Microsoft.XMLHTTP on the client.
So the statement "they do not appear to be valid objects in ASP.NET" does
not really make sense, the client has to support the objects and
XMLHttpRequest is supported by Mozilla, Netscape 7/8, Opera 8, Safari 1.2,
Konqueror 3.3, and Microsoft.XMLHTTP by IE 5 and later on Windows.
<script language="Javascript">

if (window.XMLHttpRequest) {

} else if (window.ActiveXObject) {


If something does not work as you want then it can have many reasons, if
you use Mozilla or Firefox check the JavaScript console first.
loadXMLDoc('http://www.wengert.org/'


You need to be aware that with normal security settings XMLHttpRequest can
load data only from the same HTTP server as the HTML document with the
script has been loaded from. So perhaps you are trying to access that web
service on www.wengert.org with a script in a HTML document loaded from
another server and then simply get no access.

--

Martin Honnen
http://JavaScript.FAQTs.com/

Aug 13 '05 #5

This discussion thread is closed

Replies have been disabled for this discussion.