Hi,
I am trying to record the country and city of a visitor to my website using Ajax and ASP.
The first page the user visits has the following code:
<script type="text/javascript" src="<script src="saveloc.js"></script>
<script language="javascript">
saveLoc(google.loader.ClientLocation.address.country, google.loader.ClientLocation.address.city)
</script>
saveloc.js contains my function called saveLoc. I've added a couple of lines to display the country and city to test the function is being called properly. So far so good!
var xmlhttp
function saveLoc(Country, City)
{
document.write(Country)
document.write(City)
if (Country.length==0)
{
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="savedata.asp";
url=url+"?Country="+Country;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
The bit that does not seem to be working is this:
var url="savedata.asp";
url=url+"?Country="+Country;
xmlhttp.open("GET",url,true);
My file savedata.asp currently contains the following:
<%
Response.Write("Saving data...")
%>
However this message isn't displayed and even if I include a deliberate mistake like
Responsse.Write("Test")
no error is returned - where am I going wrong please? The idea is I can then add to savedata.asp so it actually writes to my database.
Thanks very much
Ed
I am trying to record the country and city of a visitor to my website using Ajax and ASP.
The first page the user visits has the following code:
<script type="text/javascript" src="<script src="saveloc.js"></script>
<script language="javascript">
saveLoc(google.loader.ClientLocation.address.country, google.loader.ClientLocation.address.city)
</script>
saveloc.js contains my function called saveLoc. I've added a couple of lines to display the country and city to test the function is being called properly. So far so good!
var xmlhttp
function saveLoc(Country, City)
{
document.write(Country)
document.write(City)
if (Country.length==0)
{
return;
}
xmlhttp=GetXmlHttpObject();
if (xmlhttp==null)
{
alert ("Your browser does not support XMLHTTP!");
return;
}
var url="savedata.asp";
url=url+"?Country="+Country;
xmlhttp.open("GET",url,true);
xmlhttp.send(null);
}
function GetXmlHttpObject()
{
if (window.XMLHttpRequest)
{
// code for IE7+, Firefox, Chrome, Opera, Safari
return new XMLHttpRequest();
}
if (window.ActiveXObject)
{
// code for IE6, IE5
return new ActiveXObject("Microsoft.XMLHTTP");
}
return null;
}
The bit that does not seem to be working is this:
var url="savedata.asp";
url=url+"?Country="+Country;
xmlhttp.open("GET",url,true);
My file savedata.asp currently contains the following:
<%
Response.Write("Saving data...")
%>
However this message isn't displayed and even if I include a deliberate mistake like
Responsse.Write("Test")
no error is returned - where am I going wrong please? The idea is I can then add to savedata.asp so it actually writes to my database.
Thanks very much
Ed