Link to home
Start Free TrialLog in
Avatar of GoofyDawg
GoofyDawgFlag for United States of America

asked on

Out of curiosity... Anybody using ASP and XMLHTTPRequest?

Just out of curiosity, I was wondering if anyone has deployed any applications using good ol' ASP and XMLHTTPRequest. I've started doing it with a couple of sites I'm working on, and am finding it's amazingly fast and starts introducing the concept of an "application" to the web without all the overhead of let's say a Java-based framework like AF, or even the sophistication of Ruby on Rails.

Points will be awarded based on discussion and good, working examples.

Thanks!

GoofyDawg
Avatar of kiddanger
kiddanger
Flag of United States of America image

I'm not sure what you're looking for but here is a simple example of grabbing an image from a remote site, saving it, reloading it from file and then displaying it, all in binary mode.

This is the link: (notice you cannot view the source)
http://kiddanger.com/lab/getimage.asp

This is the source code:

<%@ Language=VBScript %>
<%
function GetBinaryData(filename)
  Response.ContentType = "image/gif"
  dim HTTP
  set HTTP = Server.CreateObject("MSXML2.ServerXMLHTTP")
  HTTP.Open "GET", filename
  HTTP.Send
  GetBinaryData = HTTP.responseBody
  set HTTP = nothing
end function

sub SaveBinaryFile(binaryData, path)
  dim fso, bStream
  set fso = server.CreateObject("Scripting.FileSystemObject")
  set bStream = server.CreateObject("ADODB.Stream")
  bStream.Type = adTypeBinary
  bStream.Open
  bStream.Write binaryData
  if not fso.fileExists(path) then
    bStream.SaveToFile path, adSaveCreateNotExist
  else
    bStream.SaveToFile path, adSaveCreateOverWrite
  end if
  bStream.Close
  set bStream = nothing
  set fso = nothing
End sub

Function ReadBinaryFile(FileName)
  Const adTypeBinary = 1
  Dim BinaryStream
  Set BinaryStream = CreateObject("ADODB.Stream")
  BinaryStream.Type = adTypeBinary
  BinaryStream.Open
  BinaryStream.LoadFromFile FileName
  ReadBinaryFile = BinaryStream.Read
End Function

Const strPath = "c:\domains\kiddanger.com\e\"
dim path, gifdata, file, remoteFile, imgdata
remoteFile = "http://www.google.com/intl/en/images/logo.gif"
imgdata = GetBinaryData(remoteFile)
file = "logo.gif"
path = strPath & file
SaveBinaryFile imgdata, path
gifdata = ReadBinaryFile(path)
Response.ContentType = "image/gif"
Response.Buffer = True
Response.Clear
Response.BinaryWrite gifdata
Response.Flush
%>

This is a link to grab a local (server) file and display it in a textarea.  There is a link at the bottom of the page to view the source.
http://kiddanger.com/lab/geturl2.asp

This is the file it grabs:
http://kiddanger.com/lab/plainjane.html

You can view the source to see it is an HTML file but the HTML markup is stripped when it is called from geturl2.asp.
Avatar of GoofyDawg

ASKER

That's cool, but I'm actually looking for created on a broader scale - perhaps some web application that was built using XMLHTTPRequest - Mind you - and I'm sorry I didn't mention this - I'm looking for something cross-browser as well...

GoofyDawg
Perhaps you should be more specific since 'web application' is vague.  Also, that's not cross-browser.  Test for the support and then branch, as you would with any app.
Hmm...

I hate to use the buzz word of the day, but to be specific, I'm essentially talking about AJAX. I'm looking to see if anyone has done something along these lines using ASP, such as a dedicated (and I'll correct myself here) web-based application using ASP as the "app" layer, then JavaScript/XMLHTTPRequest to handle the content.

Thanks for the input so far...

GoofyDawg
Avatar of Anthony Perkins
For the record and as has been pointed out already you should be using ServerXMLHTTP instead of XMLHTTPRequest
GD...

I haven't done any 'ajax' per se and I know it's the buzz word of the day but it's not anything new.  MSFT was doing it years ago.  It's called remote scripting.  I have an article somewhere.  In fact, I believe I already posted a link to it here on a different question.

Here, I found it.  You should read this article.  It's not only accurate and informative, it's quite humorous.
http://www.eggheadcafe.com/articles/20050528.asp

The idea is to add/update elements into your page without refreshing.  It still uses the HTTPRequest but MSFT one way and FF (for example) uses it with what is built in.  Since IE doesn't have it built-in, the ActiveX is required.  FF couldn't use the ActiveX, even if it didn't have support built-in because FF doesn't support ActiveX.  That was my reference to my previous comment re: Test for support and then branch meaning test for what the browser supports vs testing for the browser name and version and then branch accordingly in your app.

This was the other thread.  You may find it useful.
http:Q_21476930.html

That article is dead-on. Thanks for the reference. Just for clarity, I'm not new to remote scripting, but the funny thing is that up until recently, I hadn't heard of a lot of sites that were employing it to a very large degree, so I was curious to see if people were actually using it - especially with basic ASP. Now there seems to be this craze over it, especially in the non-MSFT platforms.
ASKER CERTIFIED SOLUTION
Avatar of kiddanger
kiddanger
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
What I've personally found is that your client (or whoever you're building for) has to accept the fact that changing content will not cause a page refresh - goes back to that notion of an application. I had a lot of explaining to do recently with a client when I rebuilt the content management section of their site. They kept on saying "it's on the same page!" :)

With regards to you last statement, what I found easiest was to use my ASP pages simply as content providers, and letting JavaScript and CSS handle display. But you're right, with AJAX, you do introduce another layer, so it can be a bit challenging.

GoofyDawg
Thank you GD.
Not a problem. Thanks for the discussion.