Hello there, this is my first time using these google groups..so if i'm
doing somethign wrong or in the wrong place let me know
What i'm trying to do is use the XMLHttpRequest object to send a string
to a custom script i made, and then depending on what the string
is..have the script do some work and return a value.
I'm using javascript for the XMLHttpRequest object, and sending the GET
Request to a ASP.net script (i think the problem lies in my
script)...but heres the code I guess
Here is my basic .htm javascript page
<script type="text/javascript">
var HttpObject;
function SendRequest(url)
{
HttpObject = getHttpObject();
HttpObject.open("GET", url, true);
HttpObject.onreadystatechange = getHttpResponse();
HttpObject.send(null);
}
function getHttpResponse()
{
if (HttpObject.readyState == 4)
{
alert(HttpObject.responseText);
}
else
{
alert(HttpObject.readyState);
}
}
function getHttpObject()
{
// gets the object fine so i took this part out
}
</script>
Here is where i think the trouble is..I didn't know how to make just a
stand alone asp.net script so i just made like a webpage..take a look
<ASP.NET SCRIPT PAGE>
<%@ Page Language="C#" Debug="true" %>
<%@Import namespace='System.Data' %>
<%@Import namespace='System.Data.OleDb' %>
<script type="text/C#" runat=server>
public OleDbConnection cn;
public void ConnectToDatabase()
{
cn = new OleDbConnection("connection string that you guys can't see");
cn.Open();
}
public string Str;
public string JScript;
</script>
<html>
<head runat=server>
<%
Str = Request.QueryString.Get("str");
JScript = "";
ConnectToDatabase();
string sSQL = "my sql statement";
OleDbCommand Cmd = new OleDbCommand(sSQL, cn);
OleDbDataReader Reader = Cmd.ExecuteReader();
while (Reader.Read())
{
JScript += "\"" + Reader.GetString(0) + "\",";
}
JScript = JScript.Remove(JScript.Length);
JScript += ");";
cn.Close();
Response.Write(JScript);
%>
</head>
<body>
</body>
</html>
</ASP.NET SCRIPT PAGE>
The Problem is that the ReadyState is always 1..which i think means no
request was sent...but on my button handler in the html page i have an
onClick="javascript:SendRequest('scriptpage.aspx?s tr=foobar')";
any help would be awesome..thanks