Ajax append load

被刻印的时光 ゝ 提交于 2019-12-03 03:25:22
$(document).ready(function(){    
    $.get("textes.html",function(data){
        $("#right").append($("#nicolas",data)).end().append($("#antoine",data));
    },'html');    
});
Jibou

I had a similar issue just now and I think I figured out a way to do what we want using the .load() function. It's not pretty but never mind ;)

First off, I added a "TempDiv" to my html with a "visibility:hidden" style.

<div id="TempDiv" style="visibility:hidden"></div>

Then you run the jQuery :

$(document).ready(function(){
        $('#TempDiv').load('textes.html #nicolas', function(){
            $('#right').append($('#TempDiv').html());
        });

    });

I'm not sure it's the best way !

PS : That is my first stackoverflow post ;)

AmusableLemur

try,

$.get('url.php', function(data) {
    $("#right").append(data);
});

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().

Jonathan Parker

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: Use jQuery to replace XMLHttpRequest

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!