[英]Server-side processing with pipelining
By default this function works with $_GET
. 默认情况下,此函数与
$_GET
。 Based on this discussion I modified this function and got something like below. 在此讨论的基础上,我修改了此功能,并得到如下所示的内容。 Now the problem is, Firebug gives error message
现在的问题是,Firebug给出错误消息
json.aaData is undefined @ line 99
json.aaData在第99行未定义
Here is line (located at the end of code) : 这是一行(位于代码末尾):
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
PHP side responds, and this table works 100% without pipelining. PHP方面做出了响应,并且该表在不进行流水线操作的情况下可以100%工作。 But When I enable pipelining getting this error:
但是当我启用流水线获取此错误时:
http://screencast.com/t/GOJzPHq3kg http://screencast.com/t/GOJzPHq3kg
function fnDataTablesPipeline ( sSource, aoData, fnCallback ) {
var iPipe = 5; /* Ajust the pipe size */
var bNeedServer = false;
var sEcho = fnGetKey(aoData, "sEcho");
var iRequestStart = fnGetKey(aoData, "iDisplayStart");
var iRequestLength = fnGetKey(aoData, "iDisplayLength");
var iRequestEnd = iRequestStart + iRequestLength;
oCache.iDisplayStart = iRequestStart;
/* outside pipeline? */
if ( oCache.iCacheLower < 0 || iRequestStart < oCache.iCacheLower || iRequestEnd > oCache.iCacheUpper )
{
bNeedServer = true;
}
/* sorting etc changed? */
if ( oCache.lastRequest && !bNeedServer )
{
for( var i=0, iLen=aoData.length ; i<iLen ; i++ )
{
if ( aoData[i].name != "iDisplayStart" && aoData[i].name != "iDisplayLength" && aoData[i].name != "sEcho" )
{
if ( aoData[i].value != oCache.lastRequest[i].value )
{
bNeedServer = true;
break;
}
}
}
}
/* Store the request for checking next time around */
oCache.lastRequest = aoData.slice();
if ( bNeedServer )
{
if ( iRequestStart < oCache.iCacheLower )
{
iRequestStart = iRequestStart - (iRequestLength*(iPipe-1));
if ( iRequestStart < 0 )
{
iRequestStart = 0;
}
}
oCache.iCacheLower = iRequestStart;
oCache.iCacheUpper = iRequestStart + (iRequestLength * iPipe);
oCache.iDisplayLength = fnGetKey( aoData, "iDisplayLength" );
fnSetKey( aoData, "iDisplayStart", iRequestStart );
fnSetKey( aoData, "iDisplayLength", iRequestLength*iPipe );
jQuery.post( sSource, aoData, function (data) {
/* Callback processing */
oCache.lastJson = jQuery.extend(true, {}, data);
if ( oCache.iCacheLower != oCache.iDisplayStart )
{
data.aaData.splice( 0, oCache.iDisplayStart-oCache.iCacheLower );
}
data.aaData.splice( oCache.iDisplayLength, data.aaData.length );
fnCallback(data)
},"json" );
}
else
{
json = jQuery.extend(true, {}, oCache.lastJson);
json.sEcho = sEcho; /* Update the echo for each response */
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower ); // <- this line
json.aaData.splice( iRequestLength, json.aaData.length );
fnCallback(json);
return;
}
}
What am I missing? 我想念什么? Any suggestion?
有什么建议吗?
json
gets its properties, inside fnDataTablesPipeline()
, from oCache.lastJson
but only if bNeedServer
is true. json
从oCache.lastJson
获取fnDataTablesPipeline()
内部的属性,但bNeedServer
是bNeedServer
为true。
If fnDataTablesPipeline()
has never been called or has been called but bNeedServer
remained false, then the line oCache.lastJson = jQuery.extend(true, {}, data);
如果从未调用过
fnDataTablesPipeline()
或已调用它,但是bNeedServer
保持为false,则oCache.lastJson = jQuery.extend(true, {}, data);
will not have been executed and json.aaData.splice()
will fail. 将不会被执行,并且
json.aaData.splice()
将失败。
You need to handle the case that oCache.lastJson
is not populated (or only partially populated) either: 您需要处理以下情况之一:
oCache.lastJson
未填充(或仅部分填充):
oCache.lastJson
with default properties oCache.lastJson
For example: 例如:
else{
if(oCache.lastJson.aaData) {
json = jQuery.extend(true, {}, oCache.lastJson);
json.sEcho = sEcho; /* Update the echo for each response */
json.aaData.splice( 0, iRequestStart-oCache.iCacheLower );
json.aaData.splice( iRequestLength, json.aaData.length );
fnCallback(json);
}
}
I can't tell whether this is 100% correct. 我不知道这是否100%正确。 You may need to put less inside the
if
clause, for example it may be appropriate to suppress only the two lines starting json.aaData.splice...
. 您可能需要在
if
子句中放入更少的内容,例如,只json.aaData.splice...
开头的两行可能是适当的。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.