469,349 Members | 1,577 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,349 developers. It's quick & easy.

Returning multiple values using XMLHTTP object?

Hrm.. last posting was mangled. Let's try again, with more detail...

I'm just starting to try out "Ajax" web programming and I've got a question.

AJAX is fairly straightforward. Javascript creates an XMLHttp object and
then uses that to generate a hidden webpage with your results.

What I'd like to know is, how can I retrieve multiple values from an XMLHttp
request?For example, if my request generated an SQL query that returned a
Name, Address and PhoneNumber, could I get those values directly instead of
parsing them out of the ResponseText?

This is my current handler:

function showResult(pge) {
var url="getResult.asp?sid=" + Math.random() + "&q=" + pge
xmlHttp=GetXmlHttpObject(stateChanged)
xmlHttp.open("GET", url , true)
xmlHttp.send(null)
}

function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//Complete, so show results.
document.getElementById("myResult").innerHTML=xmlH ttp.responseText;
//How to get mulitple values here?
}
}
Apr 6 '06 #1
3 9051

Noozer napisal(a):
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//Complete, so show results.
document.getElementById("myResult").innerHTML=xmlH ttp.responseText;
//How to get mulitple values here?
}
}


Response form of request made via XmlHttpObject can be anything. Here
you can do:

- generate XML Document on the server side and send it as response to
the XmlHttpObject using proper Content-type header value (either
text/xml, application/xml, or ends in +xml), than use responseXML;

- use JSON data interchange format, create desired structure on server
side and send it as response to the XmlHttpObject (here as
Content-type header value i used text/plain), than use
var myJSONdata = eval(xmlHttp.responseText);

It is good to set also Cache-Control to "no-cache" header, but
generally idea used in AjaxRequest library works in real world (adding
unique URIComponent to query string, search thru google for this free
library).

, also you can do:

var myJSONdata = JSON.parse(xmlHttp.responseText);

, using JSON implementation by Douglas Crockford (which i also have
used with success, search thru google).

Hope it helps.

Best regards
Luke M.

Apr 6 '06 #2

"Luke Matuszewski" <ma****************@gmail.com> wrote in message
news:11**********************@e56g2000cwe.googlegr oups.com...

Noozer napisal(a):
function stateChanged() {
if (xmlHttp.readyState==4 || xmlHttp.readyState=="complete") {
//Complete, so show results.
document.getElementById("myResult").innerHTML=xmlH ttp.responseText;
//How to get mulitple values here?
}
}
Response form of request made via XmlHttpObject can be anything. Here
you can do:

- generate XML Document on the server side and send it as response to
the XmlHttpObject using proper Content-type header value (either
text/xml, application/xml, or ends in +xml), than use responseXML;


Since I'm generating the data using ASP, I think that XML is the way to go.
Unfortunately I can't figure out how to do this and I'm having no luck
finding examples online.
- use JSON data interchange format, create desired structure on server
side and send it as response to the XmlHttpObject (here as
Content-type header value i used text/plain), than use
var myJSONdata = eval(xmlHttp.responseText);
JSON seems like a good idea, but again, not finding any easily understood
examples of it's usage.
var myJSONdata = JSON.parse(xmlHttp.responseText);

, using JSON implementation by Douglas Crockford (which i also have
used with success, search thru google).
Will take a look.
Hope it helps.


Definately!

Thanks!
Apr 7 '06 #3
Noozer wrote:
JSON seems like a good idea, but again, not finding any easily understood
examples of it's usage.

If you are using ASP and .NET Framework, than this will probably be the
best:

http://jayrock.berlios.de/ (if you read this site carefully, you will
see also examples).
Thanks!


People writing here in this group helped me a lot, so now i am helping
others.

Best regards !
Luke M.

PS i have used JSON without any example, but using the JSON
implementation for Java and JavaScript provided by Douglas Crockford.

Apr 7 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

7 posts views Thread by Dr John Stockton | last post: by
6 posts views Thread by Nathan | last post: by
1 post views Thread by trpost | last post: by
17 posts views Thread by Arjen | last post: by
1 post views Thread by CARIGAR | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.