Asked by stuengelman
at 2024-08-03 23:54:57
Point:500 Replies:33 POST_ID:828696USER_ID:11589
Topic:
Microsoft Development;Internet Protocols;Web Browsers
Hello,
I am trying to do a Javascript AJAX call to an ASP Classic script hosted at another domain at a different host. My Javascript and ASP Classic script appear below. The basic idea is that the ASP Classic script reads a MySQL DB table and is intended to pass back information to display within a SPAN element in the calling web page, using querystring input from the Javascript to determine which DB table record to work with.
I've tested the ASP Classic script by invoking it directly from its host in my browser, and it works perfectly. I've also set up headers in the ASP Classic script to permit cross-domain AJAX when the calling Javascript is hosted at the operant domain.
The code fails to return any result in MSIE, Firefox, and Chrome. In MSIE, I get a runtime Javascript error saying "permission denied."
Here is the Javascript code:
-------------------------------------------
function zip_onfocusout(inzip) {
var xmlhttp;
if (window.ActiveXObject) {//MSIE
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {//Other Browsers
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("statedisplay").innerText=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://www.leadtothetop.com/getstate.asp?zip="+inzip,true);
xmlhttp.send();
}
Here is the ASP Classic Script:
-----------------------------------------------
<%@ Language=VBScript %>
<!--#include file="system/adovbs.inc"-->
<%Response.AddHeader "Access-Control-Allow-Methods","GET, OPTIONS"
Response.AddHeader "Access-Control-Allow-Credentials","true"
Response.AddHeader "Access-Control-Allow-Origin","http://www.legalhelprightnow.org, http://legalhelprightnow.org"
Response.AddHeader "Access-Control-Allow-Headers","*"
if isnumeric(Request.QueryString("zip")) and Request.QueryString("zip")<>"" then
set CN=server.CreateObject("ADODB.Connection")
CN.Open "dsn=" & application("dbodbcdsn"),application("dbusername"),application("dbpassword")
set RS=server.CreateObject("ADODB.Recordset")
SQL="select State from zipcodes where ZipCode=" & Request.QueryString("zip") & ";"
RS.Open SQL,CN,adOpenStatic,adLockReadOnly
if not RS.EOF then
Response.Write("(" & RS("State") & ")")
else
Response.Write("(State Not Found)")
end if
RS.Close
set RS=nothing
CN.Close
set CN=nothing
elseif Request.QueryString("zip")<>"" then
Response.Write("(Zip Not Valid)")
else
Response.Write("")
end if%>
The basic idea is that someone enters a zip code into a textbox on the calling page, and after moving mouse focus to the next control, the AJAX call is intended to fill a SPAN element with the associated two byte state abbreviation within parentheses.
Are my ASP classic headers wrong, or is something else causing the problem?
My PC is running Windows XP, and the ASP Classic host is running Windows 2008.
Thanks very much,
Stu Engelman
I am trying to do a Javascript AJAX call to an ASP Classic script hosted at another domain at a different host. My Javascript and ASP Classic script appear below. The basic idea is that the ASP Classic script reads a MySQL DB table and is intended to pass back information to display within a SPAN element in the calling web page, using querystring input from the Javascript to determine which DB table record to work with.
I've tested the ASP Classic script by invoking it directly from its host in my browser, and it works perfectly. I've also set up headers in the ASP Classic script to permit cross-domain AJAX when the calling Javascript is hosted at the operant domain.
The code fails to return any result in MSIE, Firefox, and Chrome. In MSIE, I get a runtime Javascript error saying "permission denied."
Here is the Javascript code:
-------------------------------------------
function zip_onfocusout(inzip) {
var xmlhttp;
if (window.ActiveXObject) {//MSIE
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
} else {//Other Browsers
xmlhttp = new XMLHttpRequest();
}
xmlhttp.onreadystatechange=function() {
if (xmlhttp.readyState==4 && xmlhttp.status==200) {
document.getElementById("statedisplay").innerText=xmlhttp.responseText;
}
}
xmlhttp.open("GET","http://www.leadtothetop.com/getstate.asp?zip="+inzip,true);
xmlhttp.send();
}
Here is the ASP Classic Script:
-----------------------------------------------
<%@ Language=VBScript %>
<!--#include file="system/adovbs.inc"-->
<%Response.AddHeader "Access-Control-Allow-Methods","GET, OPTIONS"
Response.AddHeader "Access-Control-Allow-Credentials","true"
Response.AddHeader "Access-Control-Allow-Origin","http://www.legalhelprightnow.org, http://legalhelprightnow.org"
Response.AddHeader "Access-Control-Allow-Headers","*"
if isnumeric(Request.QueryString("zip")) and Request.QueryString("zip")<>"" then
set CN=server.CreateObject("ADODB.Connection")
CN.Open "dsn=" & application("dbodbcdsn"),application("dbusername"),application("dbpassword")
set RS=server.CreateObject("ADODB.Recordset")
SQL="select State from zipcodes where ZipCode=" & Request.QueryString("zip") & ";"
RS.Open SQL,CN,adOpenStatic,adLockReadOnly
if not RS.EOF then
Response.Write("(" & RS("State") & ")")
else
Response.Write("(State Not Found)")
end if
RS.Close
set RS=nothing
CN.Close
set CN=nothing
elseif Request.QueryString("zip")<>"" then
Response.Write("(Zip Not Valid)")
else
Response.Write("")
end if%>
The basic idea is that someone enters a zip code into a textbox on the calling page, and after moving mouse focus to the next control, the AJAX call is intended to fill a SPAN element with the associated two byte state abbreviation within parentheses.
Are my ASP classic headers wrong, or is something else causing the problem?
My PC is running Windows XP, and the ASP Classic host is running Windows 2008.
Thanks very much,
Stu Engelman