tags:

views:

3267

answers:

4
+2  Q: 

Ajax append load

it must be jquery

I have file text.html with 6 div in (a,b,c,d,e,f)

In another file i have a div, i like it to populate the content of a+b+c+d+e+f into that single div

I have try .load = but b remplace a i have try append, but i need a temp var

so now i am stuck

That code get the content from the file textes.html ... div #a and put the content into div #right, but the second libe REMPLACE the content of right a with right b

I like to append the content a + b NOT a over b

$(document).ready(function(){
var temp = load('textes.html #nicolas');
$('#right').append(temp);
var temp = load('textes.html #antoine');
$('#right').append(temp);
.
.
.
.

return false;
});

that code is the idea behind what should work, but i cannot make a ajax .load() to load content into a variable to append the content to the div...

<script type="text/javascript">
$(document).ready(function(){    
$.ajax({
  url: "textes.html",
  cache: false,
  success: function(html){
    $("#right").append(html);
  }
});
});
</script>

That code load the WHOLE html file, i like to get only some selected DIV #

A: 

This sounds like jQuery? Please state what framework you are using since I can't really see any mention of it. Anyway, append should work. Just do something like:

mydiv.append(a.text());
mydiv.append(b.text());
mydiv.append(c.text());
mydiv.append(d.text());
mydiv.append(e.text());
mydiv.append(f.text());

They should all be appended into mydiv. NOTE: if you also want the html, use the .html() function instead of .text().

Ko9
The div that he wants to load the data into is in another html file so this won't work.
Jonathan Parker
A: 

JQuery ( http://jquery.com/ ) is a good javascript library that you can use to do an AJAX request to get the other file. See this question for more: http://stackoverflow.com/questions/104323/use-jquery-to-replace-my-xmlhttprequest

Jonathan Parker
+4  A: 
$(document).ready(function(){    
    $.get("textes.html",function(data){
        $("#right").append($("#nicolas",data)).end().append($("#antoine",data));
    },'html');    
});
Chad Grant
result : nothing.. empty !
marc-andre menard
if fact do you have a simple method to get the .load() content into a var, i will append everything into that var and push it into the div at the end !
marc-andre menard
marc, .load() is asynchronous so you can't call it the way you are trying to. I didn't test that code, but that is the way its done. .load() is just a wrapper around $.get which is a wrapper around $.ajax http://docs.jquery.com/Ajax
Chad Grant
that code load the WHOLE file<script type="text/javascript">$(document).ready(function(){ $.ajax({ url: "textes.html", cache: false, success: function(html){ $("#right").append(html); }});});</script>hod to select witch div i like to get from that file ?
marc-andre menard
$(html).find("#ID")
Chad Grant
A: 

Where its all beagin again?

GMK HUSSAIN