/    Sign up×
Community /Pin to ProfileBookmark

AJAX: Can more then one div be updated by one function

I have a question. Is it possible to update more then one div/span/etc using one ajax function.

If so what have I to add here?

[code]
function updateNewContent(){

if(http.readyState == 4){
document.getElementById(‘mySentence’).innerHTML = http.responseText;
}
}
[/code]

And how I will specify in server side code which div should be updated with what information?

to post a comment
JavaScript

5 Comments(s)

Copy linkTweet thisAlerts:
@NaldzNov 17.2006 — What you really mean is, you want a single ajax call to the server to return different kinds of data and display those data in different divs or spans. You can user the responseXml of your http, but doing that requires that you set your server side script to return data in xml format and using DOM in javascript you can fill different html containers with the appropiate info.
Copy linkTweet thisAlerts:
@sovikauthorNov 17.2006 — Is it the only way to do it??

Can you post any link(s) with somekind of tutorial of how set data in xml format and how to use DOM??
Copy linkTweet thisAlerts:
@NaldzNov 17.2006 — Try googling Javascript DOM and as for the data in xml format, it depends on the server scripting language you are using.
Copy linkTweet thisAlerts:
@intriviousNov 17.2006 — The data you return could have multiple information fields delimited by '~'

Then in your AJAX function, just split("~") the data and one div could be the first part, the another div could be the second part of the split and so on.
Copy linkTweet thisAlerts:
@HattitudeNov 17.2006 — Another option (if you don't want to use XML) is to use JSON.

http://www.json.org/js.html
×

Success!

Help @sovik spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.6,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...