473,385 Members | 1,798 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

XMLHttpRequest running a ASP.net Script

K
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

Sep 9 '05 #1
2 3666
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?

-Brendan

Sep 10 '05 #2
K
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Chris Smith | last post by:
Been banging my head against this one for some time. I'm attempting to use XmlHTTPRequest to read an XML document from the web server and interact with it using the DOM. So far, I've had less...
7
by: SE | last post by:
Hi all, Apologies if this has been done before. I am trying to do some stuff with XMLHttpRequest in mozilla but no dice. I have finally pared everything down to the minimum to see what is...
21
by: Joe Attardi | last post by:
Hey all! I was reading over at the IE Blog the other day http://http://blogs.msdn.com/ie/] and read some interesting, and encouraging news. According to Sunava Dutta, an IE Program Manager,...
10
by: test | last post by:
Hi, I want to asynchronously recieve large amount of data using XMLHTTPRequest. If it is possible, I would like to make a progress bar to show the user how the process is going. According to...
9
by: Phil_Harvey | last post by:
I am redoing my website and trying to get it to do something more exciting using Javascript. I did normal Java at university and code at work in VB.NET. I have got reasonably far into what I want...
2
by: yawnmoth | last post by:
Say I have the following script: <script> var xmlHttp = false; // http://blogs.msdn.com/ie/archive/2006/01/23/516393.aspx if (window.XmlHttpRequest) { alert("part 1"); xmlHttp = new...
1
by: geevaa | last post by:
http://www.phpbuilder.com/columns/kassemi20050606.php3 XMLHttpRequest and AJAX for PHP programmers James Kassemi Introduction: Although the concept isn't entirely new, XMLHttpRequest...
4
by: Dave | last post by:
I am having some difficulties getting some inline js code to run when retrieved via AJAX by XMLHTTPRequest. Basically I am running a php script every 15 secs or so that does a query of a mysql...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.