heihe view中cnki搜索添加了无返回结果的判断

This commit is contained in:
Li Jianxuan 2011-11-28 02:41:26 +00:00
parent 66da794226
commit 9df01d3cbe
2 changed files with 23 additions and 15 deletions

View File

@ -953,6 +953,8 @@ class ServiceController extends Zend_Controller_Action
foreach ($matchs[1] as $k=>$v){ foreach ($matchs[1] as $k=>$v){
if($k < $max) $rev[$k]['url']=$v; if($k < $max) $rev[$k]['url']=$v;
} }
}else{
$error = "无搜索结果";
} }
if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)</span>#i",$body,$matchs,PREG_PATTERN_ORDER)) if(preg_match_all("#<span class=\"search_result_snap\" >(.+?)</span>#i",$body,$matchs,PREG_PATTERN_ORDER))
@ -962,7 +964,7 @@ class ServiceController extends Zend_Controller_Action
} }
} }
$response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword); $response=array("result"=>$rev,"count"=>$max,"morelink"=>'http://search.cnki.net/search.aspx?q='.$keyword,"error"=>$error);
$rev = Zend_Json::encode($response); $rev = Zend_Json::encode($response);
return $rev; return $rev;

View File

@ -480,14 +480,20 @@ function cnkiSearch(keyword){
success:function(html){ success:function(html){
var items = []; var items = [];
var obj = jQuery.parseJSON(html); var obj = jQuery.parseJSON(html);
$.each(obj.result, function(key, val) { alert(obj.error);
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'<a/></p><p><span>' if(obj.error != '')
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>' {
+val['content'] items.push('<li>' + obj.error + '</li>');
+'</p>'; }else{
$.each(obj.result, function(key, val) {
var html = '<p><a href="' +val['url']+'" target="_blank">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
+val['content']
+'</p>';
items.push('<li>' + html + '</li>'); items.push('<li>' + html + '</li>');
}); });
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>'); items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('html').height()}, 'slow'); $('html, body').animate({scrollTop:$('html').height()}, 'slow');