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){
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))
@ -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);
return $rev;

View File

@ -480,6 +480,11 @@ function cnkiSearch(keyword){
success:function(html){
var items = [];
var obj = jQuery.parseJSON(html);
alert(obj.error);
if(obj.error != '')
{
items.push('<li>' + obj.error + '</li>');
}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>'
@ -488,6 +493,7 @@ function cnkiSearch(keyword){
items.push('<li>' + html + '</li>');
});
}
items.push('<li class="more"><a href="'+obj.morelink+'" target="_blank">查看更多搜索结果</a></div>');
$('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('html').height()}, 'slow');