Passing data via XMLHTTPRequest... How do YOU do it?


N

Noozer

I've been doing some reading about "AJAX" and it sounds pretty interesting.
While I can make it work, it seem like I'm doing much of it the "hard way".
I was wondering what kind of code that others use to pass data via
XMLHTTPRequest.

My code is usually in ASP, with VBScript or Javascript for the client side
of things. I've done a bit of PHP as well. Definately not an expert by any
means, but I do understand programming - I just don't know what
elements/objects/methods/etc. are available.

So, consider the following and tell me what you'd do. Sample code is great
as well.


Address book type web application, but page contains info from two seperate
queries. User enters a name in one area of the page and clicks Search. The
XMLHTTPRequest object hits an ASP page and populates the related fields
(Name, age, SIN, etc.) in the clients screen, keeping other elements in the
page intact. What if the returned data contained a binary, like a photo?

Would you have the ASP page return a simple HTML document and parse out the
"responseText" property to find your field data? How about having the ASP
page generate a XML response and using the "responseXML" property as an
"object" containing the required information?

I guess I'm just trying to get my head around how I'd be passing different
types of information from my server side page using the XMLHTTPRequest
object. It seems like such a simple thing, but looks much more complicated
in any samples that I can find.
 
Ad

Advertisements

N

Noozer

Noozer said:
I've been doing some reading about "AJAX" and it sounds pretty
interesting. While I can make it work, it seem like I'm doing much of it
the "hard way". I was wondering what kind of code that others use to pass
data via XMLHTTPRequest.

....and to make matters worse, I just discovered JSON. Looks like a breeze
client side. But how to create the JSON object in my ASP code on the server?
 
N

Noozer

...and to make matters worse, I just discovered JSON. Looks like a

Thanks. I've actually visited many of those pages.

While I can find many examples of client side scripting, I'm having a hard
time finding examples of server side code generating a practical response.

<%
'Delcare and instanciate a "Person" object
dim oPerson
set oPerson = new cPerson

'Fill our object with data
oPerson.name="Bob Smith"
oPerson.age=36
oPerson.address.street="123 Main Street"
oPerson.address.city="Salem"
oPerson.address.state="OR"

'How do I return this Person to my JSON enabled javascript?
'How about XML enabled javascript?

%>
 
V

VK

Noozer said:
'How do I return this Person to my JSON enabled javascript?

Go to the official JSON site <http://www.json.org> and get the most
appropriate server-side module. I hope that between PHP, Perl and
Python you'll find something that fits your server.
 
A

Anthony Jones

Noozer said:
http://www.google.com/search?ie=UTF-8&oe=UTF-8&sourceid=gd&q=xmlhttprequest+JSON

Thanks. I've actually visited many of those pages.

While I can find many examples of client side scripting, I'm having a hard
time finding examples of server side code generating a practical response.

<%
'Delcare and instanciate a "Person" object
dim oPerson
set oPerson = new cPerson

'Fill our object with data
oPerson.name="Bob Smith"
oPerson.age=36
oPerson.address.street="123 Main Street"
oPerson.address.city="Salem"
oPerson.address.state="OR"

'How do I return this Person to my JSON enabled javascript?
'How about XML enabled javascript?

%>

If you're serious about JSON then why not use Javascript server side as
well?
 
Ad

Advertisements

B

blueapricot416

I have been wondering the same thing.

It looks like you are using Classic ASP, and it turns out you can just
make the XMLHTTPRequest to an ASP page that sends a regular
Response.Write with the string you want to return!

See:
http://tinyurl.com/nvbcf

Hope this helps,
Blue Apricot
 
Ad

Advertisements

N

Noozer

I have been wondering the same thing.

It looks like you are using Classic ASP, and it turns out you can just
make the XMLHTTPRequest to an ASP page that sends a regular
Response.Write with the string you want to return!

But... I want raw data returned in the response. The javascript on the
client side will do the work of presenting it to the user.

I'm trying to figure out how I should be generating and returning multiple
pieces of data from the server, to be handled by the client side script.

In my previous example...

oPerson.name="Bob Smith"
oPerson.age=36
oPerson.address.street="123 Main Street"
oPerson.address.city="Salem"
oPerson.address.state="OR"

.... I'd want my javacript to be able to pull these values from the response,
whether it be in plain HTML, XML or JSON. Right now, JSON "appears" to be
the best way to handle this on the client side - but for text data I could
even just fill in a bunch of <spans> and refer to thier InnerText by their
ID.
 

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

Top