开发者

JQuery - ajax load

Some content...

Now I need to load some file into inner-block, but save it's old content.

$('#inner').load( 'pathToFile.html' );

Will r开发者_StackOverflow社区eplace old content of div.

Thanks.


So, as I understand my code should be:

old = $('#inner').html();
$('#inner').load( 'pathToFile.html' );
$('#inner').html( old + $('#inner').html() );

?


I'd recommend against using stuff like 'load' and the other ajax helpers. They're just wrappers around $.ajax. Off the top of my head, maybe you want:

$.ajax( {
  url: 'pathToFile.html',
  type: 'get',
  success: function( r ) {
    $('#inner').append( r );
  }
} );


Instead of the way you doing you need to look at these functions ..

append( content )   Returns: jQuery

Append content to the inside of every matched element.

appendTo( selector )    Returns: jQuery

Append all of the matched elements to another, specified, set of elements. As of jQuery 1.3.2, returns all of the inserted elements.

prepend( content )  Returns: jQuery

Prepend content to the inside of every matched element.

prependTo( selector )   Returns: jQuery

and yes @thenduks method is a better way.


var oldHtml = $('#inner').html();
$('#inner').load( 'pathToFile.html' );


var originalContent=$('#inner').html();
$('#inner').load( 'pathToFile.html' );

is that what you are after?

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜