473,499 Members | 1,510 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 9538

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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
3825
by: Dr John Stockton | last post by:
What are the best ways of returning multiple results from a subroutine ? I've been using ... return } which is inelegant. I'm used to Pascal's procedure X(const A, B : integer; var C, D :...
17
43868
by: Roland Hall | last post by:
Is there a way to return multiple values from a function without using an array? Would a dictionary object work better? -- Roland Hall /* This information is distributed in the hope that it...
6
7243
by: Nathan | last post by:
Can I run two XMLHTTPRequest objects at the same time? Im able to get one to work without problems. If I put a call to a function inside the first ones onreadystatechange function, the 2nd ones...
1
8196
by: trpost | last post by:
How can I accomplish the following using AJAX / PHP: I have a form with a text field and a search button next to the text field. When I type something in the text field and hit the search button...
5
2432
by: salvador | last post by:
I'm trying to create a function to return some values from a php script. The php script is returning the correct values if called from a browser window. However, the function that I'm using never...
17
11835
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
4
4637
by: sufian | last post by:
Below is the field where user enters his/her email address and the AJAX post request is sent to the server and the user sees the message: echo("<div id=\"message\" class=\"success\">Thank you! You...
4
2384
omerbutt
by: omerbutt | last post by:
hi there i am making an application in which i have a drop down menu which onchange passes a value(this.value) to a js function which gets the value and calls an ajax routine and passes that value...
21
3797
vikas251074
by: vikas251074 | last post by:
I am getting error while entry in userid field. When user enter his user id, an event is fired immediately and user id is verified using AJAX method. But I am getting error 'Object doesn't support...
0
7130
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
7171
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7220
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
6893
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
5468
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
1
4918
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3098
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
3090
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1427
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.