Feed on
Posts
Comments
Email訂閱

抓取query string之後,當作ajax call的輸入參數包裝成json物件,成功執行後再將iteration的改變值再轉換成query string,以jQuery寫到page-nav物件,以動態網頁方式做為iteration的狀態儲存。

sample code,假設有一div內容為
<div id='page-nav'><a href='/ajaxserver/myajaxfunc?start=0&limit=10&userid=5'></a></div>

$ajaxfunc = $("#page-nav > a");
var o = parseUri.options;
var items = parseUri($ajaxfunc.attr("href"));
var query = items[o.q.name];
ajaxurl= items["path"];

var start = parseInt(query["start"]);
var limit = parseInt(query["limit"]);
//var cbFunc = query["cb"];
var action = query["action"];
var actionparams = query["actionparams"];

var $container = jQuery("#page-nav").parent();
var jsondata = eval('(' + array2json(query) + ')');

jQuery.ajax({
url: ajaxurl,
data: jsondata,
success: function(response) {
if(response != ""){
var e = document.createElement('div');
$e = jQuery(e).append(response).appendTo($container);
docobj.AfterIteration(e, action, actionparams);

$container.imagesLoaded( function(){
$container.masonry('appended', $e);
});

//make new iteration
query["start"] = start+limit;
var querystring = makeQS(query);
$ajaxfunc.attr("href", ajaxurl+"?"+querystring);
}
else {
scrolleventlock =false;
jQuery("#page-nav").remove();
}
}
});

相關文章

留言區