ajax or toggle to load HTML content into DIV
i am displaying ht开发者_如何学Goml content onclick of a button . is it better to just toggle it or use ajax to load it
It really depends on how big the content size is and it is static. If the content is static and small - may be toggling is better otherwise I would suggest using Ajax.
Also depends if you are concerned about SEO, since search engines won't see the content if you have to load it on a button click.
there are advantages and disadvantages to both. if it is only a tiny bit of content you are loading then a simple hide and show should suffice. plus all the content is on the same page to begin with for seo.
if its big block of content you are loading in then ajax would be the better method. reducing initial load times. also if javascript is turned off and you use the ajax example below then the user can still get to your content via the link.
//toggle example
$("a").click(function(e){
//prevent default
e.preventDefault();
$("div").toggle("slow");
});
//ajax example
$("a").click(function(e){
//prevent link default action
e.preventDefault();
//get links href
var href = $(this).attr("href");
//load the content
$("div").load(href);
});
精彩评论