修改了相关搜索的json数据加载方式

This commit is contained in:
Li Jianxuan 2012-04-16 05:51:51 +00:00
parent 46bbfe88a7
commit f71146bf2f
1 changed files with 12 additions and 8 deletions

View File

@ -546,9 +546,8 @@ $('.scholar').click(function(){scholarSearch('<?php echo $ev;?>');});
function googleSearch(keyword){ function googleSearch(keyword){
$.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword, $.ajax({type:"POST",url:"/service/googlesearch",data:'q='+keyword,
success:function(html){ success:function(obj){
var items = []; var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.responseData.results, function(key, val) { $.each(obj.responseData.results, function(key, val) {
var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>' var html = '<p><a href="' +val['unescapedUrl']+'">'+val['title']+'<a/></p><p><span>'
+val['url'].replace(/%(.*)/i,"") +'</span></p><p>' +val['url'].replace(/%(.*)/i,"") +'</span></p><p>'
@ -560,16 +559,17 @@ function googleSearch(keyword){
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow'); $('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
}, },
dataType:"json",
error:function(){alert("处理中发生错误,请刷新页面后重试");},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');} beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
}); });
} }
function scholarSearch(keyword){ function scholarSearch(keyword){
$.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword, $.ajax({type:"POST",url:"/service/scholarsearch",data:'q='+keyword,
success:function(html){ success:function(obj){
//$('#searchlist').html(html);return false; //$('#searchlist').html(html);return false;
var items = []; var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '') if(obj.error != '')
{ {
items.push('<li>' + obj.error + '</li>'); items.push('<li>' + obj.error + '</li>');
@ -586,15 +586,16 @@ function scholarSearch(keyword){
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow'); $('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
}, },
dataType:"json",
error:function(){alert("处理中发生错误,请刷新页面后重试");},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');} beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
}); });
} }
function bingSearch(keyword){ function bingSearch(keyword){
$.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword, $.ajax({type:"POST",url:"/service/bingsearch",data:'q='+keyword,
success:function(html){ success:function(obj){
var items = []; var items = [];
var obj = jQuery.parseJSON(html);
$.each(obj.SearchResponse.Web.Results, function(key, val) { $.each(obj.SearchResponse.Web.Results, function(key, val) {
var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>' var html = '<p><a href="' +val['Url']+'">'+val['Title']+'<a/></p><p><span>'
+val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>' +val['DisplayUrl'].replace(/%(.*)/i,"") +'</span></p><p>'
@ -606,15 +607,16 @@ function bingSearch(keyword){
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow'); $('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
}, },
dataType:"json",
error:function(){alert("处理中发生错误,请刷新页面后重试");},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');} beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
}); });
} }
function cnkiSearch(keyword){ function cnkiSearch(keyword){
$.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword, $.ajax({type:"POST",url:"/service/cnkisearch",data:'q='+keyword,
success:function(html){ success:function(obj){
var items = []; var items = [];
var obj = jQuery.parseJSON(html);
if(obj.error != '') if(obj.error != '')
{ {
items.push('<li>' + obj.error + '</li>'); items.push('<li>' + obj.error + '</li>');
@ -632,6 +634,8 @@ function cnkiSearch(keyword){
$('#searchlist').html(items.join('')); $('#searchlist').html(items.join(''));
$('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow'); $('html, body').animate({scrollTop:$('#searchlist').offset().top}, 'slow');
}, },
dataType:"json",
error:function(){alert("处理中发生错误,请刷新页面后重试");},
beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');} beforeSend:function(){$('#searchlist').html('<img src="/images/loading.gif" />结果加载中');}
}); });
} }