phprpc javascript
前几天用phprpc的JavaScript客户端,调用server端的方法的时候想判断server端是不是可访问的,看了看源代码,才明白了
方法1:
var client = new PHPRPC_Client('http://localhost:8088/sms/servlet/SmsCar',['method']);
这种方法不用连接到服务器就可以初始化 method 方法,初始化的时候不能判断服务器端是否可访问。
方法2:
var client = new PHPRPC_Client('http://localhost:8088/sms/servlet/SmsCar');
这种方法要连接到服务器端初始化。
如果client.getReady() 为true,表明client初始化成功,可以访问。
php分页类
来源:http://topic.csdn.net/u/20090518/09/ce1ae38a-3267-47f0-b150-0a87a5f6ff08.html
<?php
/**
* Page navigation class
* bailing
* http://gudai.cnblogs.com/
* 共有记录:147条 每页显示5条 页次:1/15 首页 上一页 下一页 尾页
* 2009
*/
class pageNav {
var $pageLink="{{link}}_{{page}}.html";
var $selectPageLink= "'{{link}}_'+this.value+'.html'";
var $page = null;
var $totalPages = null;
function pageNav( $page , $limit , $total )
{
$this->totalPages = 0;
if($total>0)
$this->totalPages = intval(ceil($total/$limit));
$this->page = min($this->totalPages , $page);
$this->limit = $limit;
$this->total = $total;
}
function getHtml()
{
$html = '';
$total_pages = $this->totalPages;
$prep = max(1,($this->page-1));
$nextp = min($this->totalPages,($this->page+1));
$firstLink = str_replace("{{page}}","1",$this->pageLink);
$lastLink = str_replace("{{page}}",$this->totalPages,$this->pageLink);
$preLink = str_replace("{{page}}",$prep,$this->pageLink);
$nextLink = str_replace("{{page}}",$nextp,$this->pageLink);
if ( $this->page> 1) {
$html .= "\n <a href='".$firstLink."' > 首页 </a>";
$html .= "\n <a href='".$preLink."' > 上一页 </a>";
} else {
$html .= "\n <span class=\"pagenav\">首页 </span>";
$html .= "\n <span class=\"pagenav\">上一页 </span>";
}
if ( $this->page < $this->totalPages ) {
$end_page = $total_pages;
$html .= "\n <a href='".$nextLink."' > 下一页 </a>";
$html .= "\n <a href='".$lastLink."' > 尾页 </a>";
} else {
$html .= "\n <span class=\"pagenav\">下一页 </span>";
$html .= "\n <span class=\"pagenav\">尾页 </span>";
}
$html = "共有记录:".$this->total."条 每页显示".$this->limit."条 页次:".$this->page."/".$this->totalPages . $html ;
return $html;
}
}//end class
?>
$limit = 12;
$baseLink = "/comment/".$id."_{{page}}.html";
$this->tpl->set( "baseLink" , $baseLink );
list( $total , $limitstart , $limit ) = pagerNew( $this->DB , "tab_ly" , $where , $tpl , $limit , $p , $baseLink );
//调用方法,大家能看懂吧。
function pagerNew( $DB , $table , $where , &$tpl , $limit=30 , $p=1 , $baseLink="/index.php" , $total=0 )
{
LoadAPI("pageNav3");
if(!$p)
{
$p = intval($_GET['p']);
if($p <=0)$p=1;
}
//计算开始条数
$limitstart = ($p-1)*$limit;
//统计共有记录数
if(!$total)
{
$q2 = "SELECT count(*) FROM ".$table." $where" ;
$DB->setQuery( $q2 );
$total = $DB->loadResult();
}
if($limitstart>=$total )
{
$limitstart = $total-$total%$limit;
if($total>0)
die("参数错误,无此页码");
}
if( $limitstart <0 )$limitstart=0;
$tpl->set( "baseLink" , $baseLink );
if($total>0)
{
$nav = new pageNav( $p , $limit , $total );
$nav->pageLink = $baseLink;
$pageLinks = $nav->getHtml();
$thispage = max($nav->page,1);
$tpl->set( "pageLinks",$pageLinks);
$tpl->set( "p",$thispage);
$tpl->set( "totalPages",$nav->totalPages);
}
else
{
$tpl->set( "p",1);
$tpl->set( "totalPages",1);
}
$tpl->set( "total",$total);
//echo $limitstart;
return array( $total , $limitstart , $limit );
}
/**
* Page navigation class
* bailing
* http://gudai.cnblogs.com/
* 共有记录:147条 每页显示5条 页次:1/15 首页 上一页 下一页 尾页
* 2009
*/
class pageNav {
var $pageLink="{{link}}_{{page}}.html";
var $selectPageLink= "'{{link}}_'+this.value+'.html'";
var $page = null;
var $totalPages = null;
function pageNav( $page , $limit , $total )
{
$this->totalPages = 0;
if($total>0)
$this->totalPages = intval(ceil($total/$limit));
$this->page = min($this->totalPages , $page);
$this->limit = $limit;
$this->total = $total;
}
function getHtml()
{
$html = '';
$total_pages = $this->totalPages;
$prep = max(1,($this->page-1));
$nextp = min($this->totalPages,($this->page+1));
$firstLink = str_replace("{{page}}","1",$this->pageLink);
$lastLink = str_replace("{{page}}",$this->totalPages,$this->pageLink);
$preLink = str_replace("{{page}}",$prep,$this->pageLink);
$nextLink = str_replace("{{page}}",$nextp,$this->pageLink);
if ( $this->page> 1) {
$html .= "\n <a href='".$firstLink."' > 首页 </a>";
$html .= "\n <a href='".$preLink."' > 上一页 </a>";
} else {
$html .= "\n <span class=\"pagenav\">首页 </span>";
$html .= "\n <span class=\"pagenav\">上一页 </span>";
}
if ( $this->page < $this->totalPages ) {
$end_page = $total_pages;
$html .= "\n <a href='".$nextLink."' > 下一页 </a>";
$html .= "\n <a href='".$lastLink."' > 尾页 </a>";
} else {
$html .= "\n <span class=\"pagenav\">下一页 </span>";
$html .= "\n <span class=\"pagenav\">尾页 </span>";
}
$html = "共有记录:".$this->total."条 每页显示".$this->limit."条 页次:".$this->page."/".$this->totalPages . $html ;
return $html;
}
}//end class
?>
$limit = 12;
$baseLink = "/comment/".$id."_{{page}}.html";
$this->tpl->set( "baseLink" , $baseLink );
list( $total , $limitstart , $limit ) = pagerNew( $this->DB , "tab_ly" , $where , $tpl , $limit , $p , $baseLink );
//调用方法,大家能看懂吧。
function pagerNew( $DB , $table , $where , &$tpl , $limit=30 , $p=1 , $baseLink="/index.php" , $total=0 )
{
LoadAPI("pageNav3");
if(!$p)
{
$p = intval($_GET['p']);
if($p <=0)$p=1;
}
//计算开始条数
$limitstart = ($p-1)*$limit;
//统计共有记录数
if(!$total)
{
$q2 = "SELECT count(*) FROM ".$table." $where" ;
$DB->setQuery( $q2 );
$total = $DB->loadResult();
}
if($limitstart>=$total )
{
$limitstart = $total-$total%$limit;
if($total>0)
die("参数错误,无此页码");
}
if( $limitstart <0 )$limitstart=0;
$tpl->set( "baseLink" , $baseLink );
if($total>0)
{
$nav = new pageNav( $p , $limit , $total );
$nav->pageLink = $baseLink;
$pageLinks = $nav->getHtml();
$thispage = max($nav->page,1);
$tpl->set( "pageLinks",$pageLinks);
$tpl->set( "p",$thispage);
$tpl->set( "totalPages",$nav->totalPages);
}
else
{
$tpl->set( "p",1);
$tpl->set( "totalPages",1);
}
$tpl->set( "total",$total);
//echo $limitstart;
return array( $total , $limitstart , $limit );
}