By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,165 Members | 849 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,165 IT Pros & Developers. It's quick & easy.

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

P: n/a
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.
Apr 10 '06 #1
Share this Question
Share on Google+
7 Replies


P: n/a

"Noozer" <do*******@me.here> wrote in message
news:s5k_f.11242$nf7.6613@pd7tw1no...
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?
Apr 10 '06 #2

P: n/a
Noozer wrote:
"Noozer" <do*******@me.here> wrote in message
news:s5k_f.11242$nf7.6613@pd7tw1no...
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?


http://www.google.com/search?ie=UTF-...tprequest+JSON
--
Microsoft MVP - ASP/ASP.NET
Please reply to the newsgroup. This email account is my spam trap so I
don't check it very often. If you must reply off-line, then remove the
"NO SPAM"
Apr 10 '06 #3

P: n/a
>> ...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?


http://www.google.com/search?ie=UTF-...tprequest+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?

%>
Apr 10 '06 #4

P: n/a
VK

Noozer wrote:
'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.

Apr 10 '06 #5

P: n/a

"Noozer" <do*******@me.here> wrote in message
news:nEy_f.57$7a.17@pd7tw1no...
...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?

http://www.google.com/search?ie=UTF-...tprequest+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?


Apr 11 '06 #6

P: n/a
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

Apr 14 '06 #7

P: n/a

<bl************@gmail.com> wrote in message
news:11**********************@u72g2000cwu.googlegr oups.com...
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.

Apr 15 '06 #8

This discussion thread is closed

Replies have been disabled for this discussion.