Code from the other thread:
var loadTextFromID=function(id){
var content=document.getElementById(id).innerHTML;
var hypeElements=document.getElementsByClassName(id);
for(i=0;i<hypeElements.length;i++){
hypeElements[i].innerHTML=content;
}
}
loadTextFromID('post1_headline');
loadTextFromID('post1_body');
As I mentioned this function writes the data found in a ID to all elements that have the same Classname.
So for example the content from the DIV with ID post1_headline
is written into the all elements that have the class post1_headline
.
As @DBear mentioned keeping the data in some format that is easy to convert into a data structur would be beneficial and make thing easier. Once you got that use something like this… (untested) tweak from the previous function:
var writeContentToClass=function(content, cl){
var hypeElements=document.getElementsByClassName(cl);
for(i=0;i<hypeElements.length;i++){
hypeElements[i].innerHTML=content;
}
}
//in your success clause and assuming you got a JSON return with data.user, data.pwd etc.
writeContentToClass( data.user, 'dataUser' );
writeContentToClass( data.pwd, 'dataPwd' );
You might ask why I am writing to class an here are the two reasons:
- Most important: Hype has a unique approach when it comes to responsive layouts. As with scenes themselves it keeps them in own HTML braches. Meaning when you have to repeat elements per scene/layout ID’s have to be unique and it would be annoying to have to choose a different ID per scene or layout for the same content.
- Addressing the content nodes per Class allows them to be in plentiful locations and they are all updated at once without the need to target any element specifically.
I saw that you are passing around password in your server response. If this isn’t secured by some two-way handshake I wouldn’t expose that access point to your userdata in a open ajax endpoint. A user able to read code could take advantage of that.