Is This "AJAX"?

B

blueapricot416

I have some javascript in a standard HTML page that uses the ubiquitous
"XMLHttpRequest" to send data to a remote ASP page.

If that page "answers back" by sending a string using a simple
Response.Write, which I then use in the original HTML page to
dynamically update stuff, is this "AJAX"?

Specifically, is there anything "wrong" with sending back info from
classic ASP pages using simple Response.Writes? (Is there usually
something more required in the "answer back"? Or something that
Response.Write might not be sending, like an appropriate header "AJAX"
header?)

I mean, what I have done works! -- so I wonder if I am missing
something? It seems so easy to do -- I _MUST_ be missing something?
Right?

Thanks,
Blue Apricot
 
M

Martin Honnen

I have some javascript in a standard HTML page that uses the ubiquitous
"XMLHttpRequest" to send data to a remote ASP page.

If that page "answers back" by sending a string using a simple
Response.Write, which I then use in the original HTML page to
dynamically update stuff, is this "AJAX"?

You can call it AJAX as it uses XMLHttpRequest. You could refuse to call
it AJAX if you don't exchange XML as the X in AJAX stands for XML. But
noone cares anymore whether that terms makes much sense or whether any
of the components (Asynchronous Javascript and Xml) are really used.
 
B

blueapricot416

SOrry, it is not so much the "term" I am wondering about.

What I am wondering is:

1. Can I use "Response.Write" to send info back to the XMLHttpRequest?
2. Is there any shortcomings to doing so?

Thanks,
B.A.
 
M

Martin Honnen

1. Can I use "Response.Write" to send info back to the XMLHttpRequest?
2. Is there any shortcomings to doing so?

Sure you can use Response.Write in an ASP page to write stuff as the
response to an HTTP request. That is what Response.Write is meant for.
And it does not matter if the HTTP request is e.g. made by the browser
because the user asked to load a URI or e.g. by some script executed in
the browser. Processing a HTTP request and writing a response with ASP
does not depend on how the request was made on the client.
As with all responses your ASP makes, you should decide what
Content-Type to send and indicate that with e.g.
Response.ContentType = "application/xml"
or
Response.ContentType = "text/plain"
 
A

abcd

I have question here Martin.

Is there anyway (DHTML) to detect if the content is xml file or text.

right now what I am doing is

'xmlstring = xml file or error code in like "Error:- Error is generated so
and so"

Response.ContentType = "application/xml"
Response.write xmlstring
response.end

my client page DHTML looks like

var sTemp = xmlhttp.responseText
var i = sTemp.indexOf("Error:-") // instead of doing this I wish to detect
if thats xml or not, if xml means go ahead if not display error
if (i >= 0)
{
//display error
return false
}
var nodes = xmlhttp.responseXML.documentElement.getElementsByTagName('abcd')
 
A

Anthony Jones

abcd said:
I have question here Martin.

Is there anyway (DHTML) to detect if the content is xml file or text.

right now what I am doing is

'xmlstring = xml file or error code in like "Error:- Error is generated so
and so"

Response.ContentType = "application/xml"
Response.write xmlstring
response.end

my client page DHTML looks like

var sTemp = xmlhttp.responseText
var i = sTemp.indexOf("Error:-") // instead of doing this I wish to detect
if thats xml or not, if xml means go ahead if not display error
if (i >= 0)
{
//display error
return false
}
var nodes = xmlhttp.responseXML.documentElement.getElementsByTagName('abcd')

A client can reasonably expect to test the content type header to determine
the type of content received. If you are sending plain text then really
ought to be setting the Response.ContentType to text/plain.

if (xmlResponse.getResponseHeader("Content-Type").indexOf("application/xml")
//xml was sent

Personally I prefer to allways send XML even if there is an error. I use
error xml along the lines of:-

<error>
<number>5</number>
<description>Invalid Procedure Call</description>
<source>Somewhere</source>
<error>

Then test if the documentElement has the tag name 'error'.

Anthony.
 

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

No members online now.

Forum statistics

Threads
474,142
Messages
2,570,819
Members
47,367
Latest member
mahdiharooniir

Latest Threads

Top