469,643 Members | 1,486 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,643 developers. It's quick & easy.

XMLHttpRequest running a ASP.net Script

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();

function getHttpResponse()
if (HttpObject.readyState == 4)
function getHttpObject()
// gets the object fine so i took this part out

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

<%@ 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");

public string Str;
public string JScript;
<head runat=server>
Str = Request.QueryString.Get("str");
JScript = "";

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 += ");";


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

Sep 9 '05 #1
2 3509
When you do this:
HttpObject.onreadystatechange = getHttpResponse();

I think what you probably mean is this:
HttpObject.onreadystatechange = getHttpResponse;

Doing it the second way will call the function getHttpResponse on every
readystatechange. If you do it the first way, instead of assigning the
function itself, you're assigning the function *result* to
onreadystatechange. And since the result is not a function, nothing
gets called when the readystate changes. Does that make sense?


Sep 10 '05 #2
Yes it does, thank's alot..that was the problem

but now...

It returns the whole asp.net webpage (isn't a problem really because i
just parse out what i need, or don't need)

but when I load the list into the <div>..for some reason..it doesn't
update it until i click on the <div>...i'm loading it in using
javascript with the div.innerHTML...any ideas on this one?

Again, thanks a lot Donius

Sep 10 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

9 posts views Thread by Chris Smith | last post: by
7 posts views Thread by SE | last post: by
1 post views Thread by geevaa | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.