0

我有这样的 Ajax 搜索框;

我想像这样更改 NotfindText:“没有结果,但你可以从这里尝试高级搜索”

但我无法添加链接。而且我对Ajax一无所知。有谁能够帮我?

function searchxx(a){(function(d){var f={blogURL:"",srcBlank:"http://1.bp.blogspot.com/-htG7vy9vIAA/Tp0KrMUdoWI/AAAAAAAABAU/e7XkFtErqsU/s1600/grey.gif",findText:"Search results for keyword",NotfindText:"No result!",Showthumb:true,LoadingText:"Searching...",scrthumbSize:50,summaryLength:100};f=d.extend({},f,a);var b=d("#ajax-search-form"),e=b.find(":text");b.append('<div id="search-result"></div>');var c=d("#search-result");b.on("submit",function(){var g=e.val();c.show().html('<div class="load">'+f.LoadingText+"</div>");d.get((f.blogURL===""?window.location.protocol+"//"+window.location.host:f.blogURL)+"/feeds/posts/default?alt=json-in-script&q="+g+"&max-results=9999",function(w){var v=w.feed.entry,r,q,u,s,h,k,m="";if(v!==undefined){m="<h4>"+f.findText+" &quot;"+g+"&quot;</h4>";m+='<a class="close" href="/">&times;</a><ol>';for(var o=0;o<v.length;o++){var l=new RegExp(g,"ig"),u=v[o].title.$t.replace(l,"<mark>"+g+"</mark>");for(var n=0,t=v[o].link.length;n<t;n++){if(v[o].link[n].rel=="alternate"){s=v[o].link[n].href}}r=("content" in v[o])?v[o].content.$t:("summary" in v[o])?v[o].summary.$t:"";if(f.Showthumb===true){var p=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;h=d("<div></div>").append(r.replace(p,""));k=h.find("img");if("media$thumbnail" in v[o]){q=v[o].media$thumbnail.url.replace(/\/s[0-9]+\-c/g,"/s"+f.scrthumbSize+"-c")}else{if(k.length!=0){q=k[0].src}else{q=f.srcBlank}}}r=r.replace(/<\S[^>]*>/g,"");if(r.length>f.summaryLength){r=r.substring(0,f.summaryLength)+"..."}r=r.replace(l,"<mark>"+g+"</mark>");m+='<li><a href="'+s+'" >'+(f.Showthumb===true?'<img width="'+f.scrthumbSize+'" height="'+f.scrthumbSize+'" src="'+q+'"/>':"")+"<strong>"+u+"</strong></a>"+(f.summaryLength>0?"<p>"+r+"</p>":"")+"</li>"}m+="</ol>";c.html(m)}else{c.html('<a class="close" href="/">&times;</a><strong>'+f.NotfindText+"</strong>")}},"jsonp");return false});b.on("click",".close",function(){c.fadeOut();return false})})(jQuery)};

这是SS:

在此处输入图像描述

4

2 回答 2

0

One thing, all the responce that will be written here is a responce caught from the page where Ajax runs. So you would be writing all the codes there instead of here.

You have not provided any of your code, that is a -1 for your question. But I won't, only thinking that you might add the code here in the question.

Ok, how to add the <a> link here is the example:

Response.Write("No result, but you can do a search <a href='~/link'>here</a>");

This way, that was the respone. Else you can use this:

success: function (data) {
  if(data == "") {
   NotfindText = "No result, but you can do a search <a href='~/link'>here</a>";
  }
}

But again, this is not what ajax would write. You are just writing the code on your own. Its of no use.

You must use success to make sure this is written once the ajax provides no result.

于 2013-09-24T14:04:30.280 回答
0

看起来不像是 AJAX 问题,您只需为 Notfindtext 键提供一个字符串。用这一行替换 Notfindtext:

NotfindText: "No results but you can try advanced search 
from <a href=\"http://google.com/\">HERE</a>",

这有帮助吗?检查您的 Chrome javascript 控制台并查看引发了哪些错误。

于 2013-09-24T14:01:10.953 回答