Thursday 15 July 2010

javascript - Ajax call loads the current content -



javascript - Ajax call loads the current content -

i have looked through many forums racking brain seek , super simple load function working. i've narrowed downwards believe selector issue on .fadein() part of loadcontent function.

i can see why keeps loading same stuff, uses same selector, based on tutorial i've been trying utilize (http://css-tricks.com/rethinking-dynamic-page-replacing-content/) other (even more broken) method did work (based on this: http://code.tutsplus.com/tutorials/how-to-load-in-and-animate-content-with-jquery--net-26), seems should work!

i've tried using $(href) selector, fades old content , doesn't load anything. tried adding alert see href was, , returned right html page followed right element id (articles/cats.html #content).

here's function itself, , if need more info, i'd glad give it! help incredibly, well, helpful!

function articleclickload () { if (modernizr.history) { var newhash = "", $content = $("#content"), $el; $("#content").on("click", "a", function() { var _link = $(this).attr("href"); var toload = $(this).attr('href')+' #content'; history.pushstate(null, null, _link); loadcontent(toload); homecoming false; }); function loadcontent(href){ $content.find("#content"); $content.fadeout(1000, function() { $("main").load(href,'', function() { $content.fadein(1000); }); }); } $(window).bind('popstate', function(){ _link = location.pathname.replace(/^.*[\\\/]/, ''); //get filename loadcontent(toload); }); } } articleclickload();

thanks!

i see 2 potential issues. .load takes url but you're adding ' #content' in click handler reason; should removed update: overlooked passing page fragment valid, forget that.

in loadcontent method, you're calling load on selector $("main"). not clear source main suppose should #content instead.

also note can remove sec parameter '' .load call. see .load documentation.

javascript jquery html ajax

No comments:

Post a Comment