开发者

load content to DIV tag on demand

I have a "comments" section on a webpage that I have hidden initially and when the user clicks the comments link the div tag (and comments) appear using the jQuery show/hide functions.

My question is: is it possible to load this content only when the comments l开发者_StackOverflow社区ink is clicked (not when the entire page is loaded)?


Given that comments_link and comments_container are the respective IDs:

$('#comments_link').click(function() {
     $('#comments_container').load('some-awesome-url-here');
});

This technique uses Ajax to make a request to a URL asynchronously and injects the resulting HTML into the specified element.

See jQuery.load


Yes... The technology you need to use is called Ajax. You can do it with jQuery or using the XMLHttpRequest object directly (not recommended).

What server technology are you using. e.g. php, .net, java,...


Yes. Use jQuery's load() function.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜