Ajax

A

Axelar

Hi :)

I wonder how to modify two div with only one click.
for example, there's a <div id="a">text</div> and a <div id="b">.

I've made a link that call a function which modify the content of div
with id a using :
if(xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText;
}

but i really don't know how to modify both div a AND div b !

Thx a lot :)
 
E

Elegie

Axelar wrote:

Hey,
I wonder how to modify two div with only one click.
for example, there's a <div id="a">text</div> and a <div id="b">.

I've made a link that call a function which modify the content of div
with id a using :
if(xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText;
}

but i really don't know how to modify both div a AND div b !

You mean, like:

if (xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText;
document.getElementById('b').innerHTML = xhr.responseText;
}

The brackets surrounding the if statement defines a block, in which you
can add as many statements as you want.
 
A

Axelar

Axelar wrote:

Hey,




You mean, like:

if (xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText;
document.getElementById('b').innerHTML = xhr.responseText;

}

The brackets surrounding the if statement defines a block, in which you
can add as many statements as you want.

First, thx for your answer.

Not exactly as div a and div b are not modified with the same
content...
To match my need it should look like:

if (xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText_1;
document.getElementById('b').innerHTML = xhr.responseText_2;
}
 
E

Elegie

Axelar said:
Not exactly as div a and div b are not modified with the same
content...
To match my need it should look like:

if (xhr.readyState == 4){
document.getElementById('a').innerHTML = xhr.responseText_1;
document.getElementById('b').innerHTML = xhr.responseText_2;
}

Ah, okay. Well, you'll either have to issue two separate XHR requests,
or issue only one which will response all data, separated by some clear
token (like a semi-colon or a pipe), which you'll parse client-side. I'd
recommend the second approach, as it would limit the number of HTTP
requests being done - but it really depends on your app.

Cheers.
 
E

Evertjan.

Elegie wrote on 15 apr 2007 in comp.lang.javascript:
Ah, okay. Well, you'll either have to issue two separate XHR requests,
or issue only one which will response all data, separated by some clear
token (like a semi-colon or a pipe), which you'll parse client-side. I'd
recommend the second approach, as it would limit the number of HTTP
requests being done - but it really depends on your app.

The response could even contain javascript:

if (xhr.readyState == 4){
eval(xhr.responseText)
}

========== Where xhr.responseText contains:

document.getElementById('a').innerHTML = 'blah';
document.getElementById('b').innerHTML = 'blip';

not recommended, as eval() is evil, but possible.
 
E

Elegie

Evertjan. wrote:

Hi Evertjan,
The response could even contain javascript:

if (xhr.readyState == 4){
eval(xhr.responseText)
}

========== Where xhr.responseText contains:

document.getElementById('a').innerHTML = 'blah';
document.getElementById('b').innerHTML = 'blip';

not recommended, as eval() is evil, but possible.

That's perfectly possible indeed, but I would not recommend it, not
because of eval (which I have nothing against), but because in such
systems only data is supposed to be transfered, and it's best to have
some pure data exchange format, like XML, JSON or custom stuff, rather
than some language-specific format/program, in case you want to use your
request in other apps, with other languages.

Cheers !
 
E

Evertjan.

Elegie wrote on 15 apr 2007 in comp.lang.javascript:
Evertjan. wrote:

Hi Evertjan,


That's perfectly possible indeed, but I would not recommend it, not
because of eval (which I have nothing against), but because in such
systems only data is supposed to be transfered, and it's best to have
some pure data exchange format, like XML, JSON or custom stuff, rather
than some language-specific format/program, in case you want to use your
request in other apps, with other languages.

That is neither here nor there, in the case that you won't want to use the
request elsewhere, and to the transfer, the javascript string is only pure
data and yes, I have nothing against custom stuff.

That you have nothing against eval(),
does not mean many will agree with you.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,431
Messages
2,571,677
Members
48,796
Latest member
Greg L.

Latest Threads

Top