Php 搜索其他站点的搜索框
站点A:开发中(PHP) 地点B: 我想在站点A中包含一个输入框;键入查询并按Enter键后,打开一个新选项卡以显示B的搜索结果。这就像我直接将搜索查询键入B一样 例如,我搜索了“testing”,并检查了来自B的搜索结果,我看到了以下内容。如何将查询从站点A传递到站点BPhp 搜索其他站点的搜索框,php,search,parameters,Php,Search,Parameters,站点A:开发中(PHP) 地点B: 我想在站点A中包含一个输入框;键入查询并按Enter键后,打开一个新选项卡以显示B的搜索结果。这就像我直接将搜索查询键入B一样 例如,我搜索了“testing”,并检查了来自B的搜索结果,我看到了以下内容。如何将查询从站点A传递到站点B <div id="search"> <form action="/Resources/SiteSearch" id="siteSearchForm" method="post"> &l
<div id="search">
<form action="/Resources/SiteSearch" id="siteSearchForm" method="post">
<label for="search-box">
SEARCH</label>
<div id="search-box-wrapper">
<input type="text" id="search-box">
</div>
<input id="searchText" name="searchText" type="hidden" value="testing"><input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q=testing">
<input type="image" src="/userfiles/images/E/buttons/go.png" id="search-button" value="GO" siteurl="www.apprenticesearch.com"><!-- www.apprenticesearch.com -->
</form>
</div>
搜寻
您只需在站点a的表单中包含target=“\u blank”,以及请求在站点B上的工作方式必须包含siteSearchUrl输入
<form id="apprenticeForm" action="http://www.apprenticesearch.com/Resources/SiteSearch" method="POST" target="_blank" onsubmit='submitSearch()'>
<input type="text" name="searchText" id="searchText" value=""/>
<input type="submit" value="Submit"/>
<input id="siteSearchUrl" name="siteSearchUrl" type="hidden" value="http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q="/>
</form>
您需要使用javascript进行额外输入的原因与Site B在发送请求之前使用javascript填充siteSearchUrl的原因相同
查看服务器的工作方式:站点B将该请求发送到/Resources/SiteSearch,在该服务器上调用SiteSearch(String searchtext,String siteSearchUrl)
函数。如果直接转到没有post参数的页面,您会发现由于没有从服务器设置siteSearchUrl,会抛出System.ArgumentNullException参数名称:uriString
如果要分析siteSearchUrl的参数:
- URL
用于API服务yboss.yahooapi.com
参数告诉API要在结果中搜索和显示的站点sites
- 而
参数就是要搜索的查询q
function updateSearch(){document.getElementById(“siteSearchUrl”).value=http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&;sites=www.peeditsearch.com&;q='+document.getElementById(“searchText”).value}
是的,您需要Javascript,我已经用代码和另一个指向JSFIDLE的链接更新了答案,显示了siteSearchUrl问题的修复方法。
function submitSearch()
{
q = document.getElementById("searchText").value;
document.getElementById("siteSearchUrl").value = 'http://yboss.yahooapis.com/ysearch/limitedweb?format=xml&sites=www.apprenticesearch.com&q=' + q;
return true;
}