ajax过滤太慢? 试试js吧

如果网页上某个AJAX过滤项目太多,次数过于频繁,服务端的压力会很大。

可以尝试将所有项目写入一个js数组,使用js正则来过滤,速度上会快很多。

当然也非绝对,过于庞大的数据,也会让浏览器吃不消。

<script>
var publisher = new Array();
<?php
for ($i = 0, $total = count($publisherArray); $i < $total; $i ++){
	$id_name = $publisherArray[$i]['Publisher']['id'].'-'.$publisherArray[$i]['Publisher']['name'];
	echo "\n publisher[$i] = '$id_name';";
}

echo "\n";
?>
</script>


re = new RegExp($('#publisher_select').val(),"gi");

for(x=0; x<publisher.length; x++){				
			pub = publisher[x].split("-");				
			pubName = pub[1].toLowerCase();
			if(pubName.search(re) !=-1){
				publisherName = (pub[1].length>21)?pub[1].substring(0,18)+'...':pub[1].substring(0,18);
				publisherList += '<li><a href="/dyco/selectpub/'+pub[0]+'/index">'+publisherName+'</a></li>';					
			}
		}


posted @ 2012-01-11 10:34  lein.wang  Views(129)  Comments(0Edit  收藏  举报