XMLHTTP response is not returning anything. Please help!

P

pbd22

All,

Need some help. My xmlhttp request isn't responding. I think it has to
do with the use of onsubmit as the calling function but, I am not
clear on what exactly is going on here. Should i be setting "return =
true" for the xmlhttp request to work? I can verify that the server
code gets called and I can step through the code in debug. But the
responseText does not alert. It seems that the response handler never
gets initiated - no alert, no nothing. I am under deadline and could
really use some help. Thanks!

So, this is the call from the onsubmit of the form tag:

<form id="form1" name="form1" onsubmit="return clientvalidation();"
method="post" action="create.aspx" enctype="multipart/form-data">

This is the script distilled:

<script type="text/javascript">

function clientvalidation(){
genericXMLHTTP("GET", "ajaxtest.aspx", "", collisionResponseHandler,
true);
}

function collisionResponseHandler(response)
{
alert(response.responseText);
}

function genericXMLHTTP(method, url, parameters, responseHandler,
asynchronous)
{
if (typeof method != 'string')
{
alert("Invalid request method.");
return false;
}

method = method.toUpperCase();

if (method != 'POST' && method != 'GET')
{
alert("Invalid request method.");
return false;
}

if (typeof parameters != 'string'){ parameters = '';}
if (typeof asynchronous == 'undefined'){ asynchronous = true;}


// build the request
var ajaxRequest = null;
if (window.XMLHttpRequest){ ajaxRequest = new
XMLHttpRequest();}
else if (window.ActiveXObject){ ajaxRequest = new
ActiveXObject("Microsoft.XMLHTTP");}

// bind the callback.
function ajaxBindCallback()
{
if (ajaxRequest.readyState == 4)
{
if (ajaxRequest.status == 200)
{
if (responseHandler)
{ responseHandler(ajaxRequest);}
}
else
{
if (ajaxRequest.status == 404)
{
alert("The requested service could not be
found.");
}
else
{
alert("There was a problem retrieving the xml
data:\n" +
ajaxRequest.status + ":\t" +
ajaxRequest.statusText + "\n" +
ajaxRequest.responseText);
}
}
}

}
// send the request
if (ajaxRequest)
{
if (asynchronous){ ajaxRequest.onreadystatechange =
ajaxBindCallback;}
if (method == "GET")
{

url = url + '?' + parameters;
parameters = null;

}

ajaxRequest.open(method, url, asynchronous);

if (method == 'POST')
{
ajaxRequest.setRequestHeader('Content-Type',
'application/x-www-form-urlencoded; charset=UTF-8');
}

ajaxRequest.send(parameters);

if (!asynchronous){ ajaxBindCallback();}

}
else
{
alert("Unable to build XMLHttpRequest");
}

}
</script>

And this is my server code (for testing):

Partial Class ajaxtest
Inherits System.Web.UI.Page


Private Sub Page_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

Response.Write("THIS WORKS")

End Sub



End Class
 
M

Martin Honnen

pbd22 said:
So, this is the call from the onsubmit of the form tag:

<form id="form1" name="form1" onsubmit="return clientvalidation();"
method="post" action="create.aspx" enctype="multipart/form-data">

Well the browser makes the HTTP request sent in the clientvalidation
function and then sends the form data which will result in an unloading
of the current document and loading of the response create.aspx sends.
Once the current document is unloaded its variables do no longer exist
and that way you should not expect the browser to process the response
sent to the HTTP request made in clientvalidation as the script to
process the response is gone.
 
P

pbd22

but i thought that the create.aspx page is sent only when the
clientvalidation()
function returns true? If i am wrong, can somebody pleas suggest how I
might get
a response from the server? I know that the server processes the
request and produces
results, but i need a way to read those results on teh client.

thanks again,
peter
 
P

pbd22

the only solution i can think of is sending all my form date with the
ajax request and return it in the response for processing.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,769
Messages
2,569,579
Members
45,053
Latest member
BrodieSola

Latest Threads

Top