ç¶ç¶ã使ã£ã¦SjaxãAjaxã«ç°¡åã«å¤æããæ¹æ³
JavaScriptによる全文検索エンジンã®æåã®ãã¼ã¸ã§ã³ã¯Ajaxã§ã¯ãªããSjaxã§ãã£ãããã®çºããµã¼ãã¸ã®ãªã¯ã¨ã¹ããçºçããæ¯ã«ãã©ã¦ã¶ãåºã¾ã£ã¦ãã¾ããå¿çæ§ãæªãã£ãããªããSjaxã§è¨è¿°ãããã¨ããã¨ãé£ç¶ãã¦ãµã¼ãã¸ãªã¯ã¨ã¹ããéãããããããµã¼ãããã®ã¬ã¹ãã³ã¹ã«å¿ãã¦ãªã¯ã¨ã¹ããå¤æ´ãããããªAjaxããã°ã©ãã³ã°ãé¢åã ã£ãçºã§ããããã®ãããªSjaxã®ã³ã¼ãä¾ã次ã«ç¤ºãï¼prototype.jsã使ç¨ï¼ã
// (Sjax)ãµã¼ãããpathã®ãã¼ã¿ãoffsetã®ä½ç½®ããlengthãã¤ãåå¾ function fetch(path, length, offset){ var range = ["bytes=" + offset + "-" + (offset + length - 1)].join(""); var options = { method: "get", asynchronous: false, requestHeaders: ["Range", range] } var request = new Ajax.Request(path, options); return request.transport.responseText; } function fetch_data(){ var path = "/data.txt"; // å é 4byteããoffsetãåå¾ var offset = parseInt(fetch(path, 4, 0)); // å é 4byteããlengthãåå¾ var length = parseInt(fetch(path, 4, 4)); // åå¾ããoffset, lengthã®ãã¼ã¿ãåå¾ãè¿å´ return fetch(path, length, offset); } alert(fetch_data);
ãã®ãããªSjaxã«ããå¦çãAjaxã«å¤æ´ããéãã©ãããã°ç°¡åã«æ¸ããããã°ããèãã¦ãããStateãã¿ã¼ã³ãã¤ãã³ããã¥ã¼ãæ¤è¨ãã¦ã¿ãããã³ã¼ãã£ã³ã°ãé¢åããã ããã³ã¼ããèªã¿é£ããªãããã ã£ããããã§ãç¶ç¶ã使ã£ã¦ã¿ãã¨ãããç°¡åã«SjaxãAjaxã«å¤æã§ããã
å ã»ã©ã®ä¾ããç¶ç¶ã使ã£ã¦Ajaxåããã¨æ¬¡ã®ããã«ãªãã
// (Ajax)ãµã¼ãããpathã®ãã¼ã¿ãoffsetã®ä½ç½®ããlengthãã¤ãåå¾ããåå¾å¾contãå®è¡ã function fetch(path, length, offset, cont){ var range = ["bytes=" + offset + "-" + (offset + length - 1)].join(""); var options = { method: "get", onComplete: function(request){cont(request.responseText);}, requestHeaders: ["Range", range] } new Ajax.Request(path, options); } function fetch_data(cont){ var path = "/data.txt"; fetch(path, 4, 0, function(offset){ offset = parseInt(offset); fetch(path, 4, 4, function(length){ length = parseInt(length); fetch(path, length, offset, function(data){ cont(data); }); }); }); } fecth_data(alert);
ç¶ç¶ã使ãæ¹æ³ã®ã¡ãªããã«ã¯æ¬¡ã®3ç¹ãããã
- å¦çã®æµãã¨ã³ã¼ãã®æµããä¸è´ããã
- åç´ä½æ¥ã§ã³ã¼ããå¤æã§ããã
- apiã®å¤æ´ãå°ãªãã
é¢æ°å¼ã³åºãã®ãã¹ããæ·±ããªãã®ãå°ã é£ç¹ã ãããããããã¡ãªããã§ã¯ãªãã¨æããå®éã«ãç¶ç¶ã使ã£ã¦名古屋市で賢い借金返済方法を教えます!ãAjaxåãã¦ã¿ãããäºæ³ããçæéã§å®è£ ã§ããã
ãªããç¶ç¶ã§ã«ã¼ããæ¸ãå ´åã«ã¯ãå帰å¼ã³åºãã«ãªããä¾ãã°ã次ã®Sjaxã³ã¼ã
function loop_fetch(l){ var data = ""; for(var i = 0; i < l; i ++){ data += fetch("/data.txt", 4, 4 * i); } return data; }
ãç¶ç¶ã使ã£ã¦Ajaxã«ããã¨ã次ã®ããã«ãªãã
function loop_fetch(l, cont){ var data = ""; var f = function(i){ if(i < l){ fetch("/data.txt", 4, 4 * i, function(rv){ data += rv; f(i + 1); }); }else{ cont(data); } } f(0); }
ç¶ç¶ãå§ãã¦ç¥ã£ãæã«ã¯ããã¾ãå½¹ã«ç«ã¤æ¦å¿µã¨ã¯æããªãã£ãããã©ããã¯ãæåãªæ¦å¿µã¯å¦ãã§ããã¦æã¯ãªãã¨æã£ãã