473,385 Members | 1,486 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 software developers and data experts.

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 9530

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
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
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
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
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
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
by: Arjen | last post by:
Hi, I want to reload 2 divs at one click. Ive tried: <a href = "javascript:void(0);"...
4
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
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
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...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.